简体   繁体   English

SQL-在where子句中正确连接VS a = b

[英]SQL - proper join VS a = b in where clause

I was just hoping someone could tell me if there is a difference in efficiency between the 2 queries below. 我只是希望有人可以告诉我以下两个查询之间的效率是否存在差异。


Query 1 查询1

SELECT A.CUSTOMER, B.INVOICE FROM CUS A

JOIN INV B ON
A.CUS_ID = B.CUS_ID

WHERE
B.INV_DATE > '2015-09-06'

Query 2 查询2

SELECT A.CUSTOMER, B.INVOICE FROM CUS A, INV B

WHERE A.CUS_ID = B.CUS_ID AND

B.INV_DATE > '2015-09-06'

I am pretty sure query 1 will be more efficient, but I was hoping someone could confirm. 我很确定查询1会更有效,但是我希望有人可以确认。

The SELECT * FROM table1, table2, ... syntax is ok for a couple of tables, but it becomes exponentially (not necessarily a mathematically accurate statement) harder and harder to read as the number of tables increases. SELECT * FROM table1,table2,...语法对于几个表是可以的,但是随着表数量的增加,它变得越来越难于指数化(不一定是数学上准确的语句)。

The JOIN syntax is harder to write (at the beginning), but it makes it explicit what criteria affects which tables. JOIN语法较难编写(在一开始),但是它使它明确表明哪些条件会影响哪些表。 This makes it much harder to make a mistake. 这使得犯错误变得更加困难。

Also, if all the joins are INNER, then both versions are equivalent. 另外,如果所有联接均为INNER,则两个版本均等效。 However, the moment you have an OUTER join anywhere in the statement, things get much more complicated and it's virtually guarantee that what you write won't be querying what you think you wrote. 但是,当您在语句中的任何位置有OUTER连接时,事情就会变得更加复杂,并且几乎可以保证您编写的内容不会查询您认为的内容。

Your performance question has been answered: there is no difference. 您的表现问题已得到解答:没有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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