Tuesday, March 27, 2012

Basic query question

Hi,
I have a basic query question and hope that someone can clarify for me.
2 queries...
#1
\\\
SELECT *
FROM
Table1 AS A
INNER JOIN Table2 AS B ON
B.Column1 = A.Column1 AND
B.Column2 = A.Column2
///
#2
\\\
SELECT *
FROM
Table1 AS A, Table2 AS B
WHERE
B.Column1 = A.Column1 AND
B.Column2 = A.Column2
///
I suppose I will get the same result among these 2 queries, I just wonder is
there any performance different between these 2 queries? Any opinion which
one is better?
Thanks in advance.it will really give you the same result
but as a matter of standard
i suggest you use the first one.
performance wise i dont know.
its just that the first one is my preferred
choice
<hr>
MCP #2324787
"Kent" wrote:

> Hi,
> I have a basic query question and hope that someone can clarify for me.
> 2 queries...
> #1
> \\\
> SELECT *
> FROM
> Table1 AS A
> INNER JOIN Table2 AS B ON
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> #2
> \\\
> SELECT *
> FROM
> Table1 AS A, Table2 AS B
> WHERE
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> I suppose I will get the same result among these 2 queries, I just wonder
is
> there any performance different between these 2 queries? Any opinion whic
h
> one is better?
> Thanks in advance.|||AFAIK, there will be no performance difference between these two
particular queries; the optimizer should recognize them as being the
same and generate an identical execution plan for them (something which
you can easily test in Query Analyzer).
I prefer the JOIN syntax because it
a) is easier to read (to me), and
b) allows you to perform more complex joins. You can easily join three
tables with an INNER JOIN between two of those tables, and an OUTER
JOIN with the last table.
HTH,
Stu|||Kent,
This issue is a old issue and I think that our gurus here could answer you
with guarantee. From my own point of view it's the same although I prefer th
e
first one.
Regards,
"Jose G. de Jesus Jr MCP, MCDBA" wrote:
> it will really give you the same result
> but as a matter of standard
> i suggest you use the first one.
> performance wise i dont know.
> its just that the first one is my preferred
> choice
> --
>
> <hr>
> MCP #2324787
>
> "Kent" wrote:
>|||Kent
No, should not be any differences bettwen two queries. See an execution
plan to make sure.
"Kent" <Kent@.discussions.microsoft.com> wrote in message
news:EBE53BFA-BCF0-437A-847C-548B447FBDD5@.microsoft.com...
> Hi,
> I have a basic query question and hope that someone can clarify for me.
> 2 queries...
> #1
> \\\
> SELECT *
> FROM
> Table1 AS A
> INNER JOIN Table2 AS B ON
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> #2
> \\\
> SELECT *
> FROM
> Table1 AS A, Table2 AS B
> WHERE
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> I suppose I will get the same result among these 2 queries, I just wonder
> is
> there any performance different between these 2 queries? Any opinion
> which
> one is better?
> Thanks in advance.|||The optimizer will recognize these doing the same thing and optimize them th
e same way. The first is
preferred and the more modern syntax.
Outer joins is another story, though... In short, don't use the old ( *= ) s
yntax.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Kent" <Kent@.discussions.microsoft.com> wrote in message
news:EBE53BFA-BCF0-437A-847C-548B447FBDD5@.microsoft.com...
> Hi,
> I have a basic query question and hope that someone can clarify for me.
> 2 queries...
> #1
> \\\
> SELECT *
> FROM
> Table1 AS A
> INNER JOIN Table2 AS B ON
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> #2
> \\\
> SELECT *
> FROM
> Table1 AS A, Table2 AS B
> WHERE
> B.Column1 = A.Column1 AND
> B.Column2 = A.Column2
> ///
> I suppose I will get the same result among these 2 queries, I just wonder
is
> there any performance different between these 2 queries? Any opinion whic
h
> one is better?
> Thanks in advance.|||Ya, they are the same in Execution Plan.
I think the first one is more neat when I get to join more tables.
Thanks all for help. :)
"Tibor Karaszi" wrote:

> The optimizer will recognize these doing the same thing and optimize them
the same way. The first is
> preferred and the more modern syntax.
> Outer joins is another story, though... In short, don't use the old ( *= )
syntax.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Kent" <Kent@.discussions.microsoft.com> wrote in message
> news:EBE53BFA-BCF0-437A-847C-548B447FBDD5@.microsoft.com...
>

No comments:

Post a Comment