简体   繁体   中英

What is the difference between using “JOIN” and “WHERE”?

I have two SQL queries one with a WHERE and one with JOIN.

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM