1

我有一个疑问。假设我得到了这个:

Invoice (Cod, CodCustomer)
Customer (Cod,Name)

我想选择 X 发票的客户名称:

SELECT Customer.Name FROM Invoice,Customer WHERE Customer.Cod = CodCustomer AND Invoice.Cod = "X"

在优化期间,如果我这样做有区别吗

Customer.Cod = CodCustomer

或者

CodCustomer = Customer.Cod

?

谢谢 :)

4

2 回答 2

0

我认为应该是

Invoice.CodCustomer = Customer.Cod

顺序并不重要,因为它只是一个比较,而且它始终是真实的。

否则,您可以使用INNER JOIN查询

SELECT a.Name 
FROM Customer a  
INNER JOIN Invoice b
ON a.Cod = b.CodCustomer 
AND b.Cod = 'X' --note single quotes, you used double wich are not correct
于 2013-06-08T11:09:29.243 回答
0

不,但是您可以在此之前执行第二个 AND。

SELECT Customer.Name FROM Invoice,Customer WHERE Invoice.Cod = "X" AND Customer.Cod = CodCustomer

如果具有Cod“x”的发票数量较少,这可能会提高您的性能。

于 2013-06-08T11:09:39.840 回答