Home SQL - Difference between two SQL queries
Reply: 2

SQL - Difference between two SQL queries

Wesgur
1#
Wesgur Published in 2018-02-13 19:09:25Z

I have two SQL queries

SELECT * FROM Table1 T1, Table2 T2 WHERE T1.Key = T2.Key AND T2.Key = T1.Key

SELECT * FROM Table1 T1 JOIN Table2 T2 ON T1.Key = T2.Key And T2.Key = T1.Key

Is there differences in the two queries? If they are the same, which one is more efficient to use?

Andomar
2#
Andomar Reply to 2018-02-13 19:12:38Z

Your first query uses ANSI-89 SQL syntax, your second query the more modern ANSI-92 join syntax. Functionally they are equivalent. The second syntax is easier to read because it keeps the condition near the joined table. That's far more visible with multiple joins.

See this question for more details.

Racil Hilan
3#
Racil Hilan Reply to 2018-02-13 19:13:26Z

Yes, both queries will give the same results. The second one uses explicit join and is the recommended one.

As for efficiency. Most database will optimize both queries to same execution plan, but very few databases may optimize the second one better.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.721447 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO