4

我有三个表,供应商、产品和交付。我想显示交货表中的供应商名称和数量。有 5 家不同的供应商,有 12 次交货。我希望连接的表应该包含 12 行名称和交货。

这是我的代码。

SELECT  Suppliers.SNAME, Deliveries.QTY
FROM Suppliers, Deliveries
INNER JOIN  Products
ON Deliveries.P=Products.Penter (typo, should be Products.P)

输出为 60 行,其中包含许多重复项和一些不正确的匹配项。

表: 供应商 产品 交货

4

2 回答 2

6

Kill off deprecated implicit joins, and specify JOIN criteria, not sure of your table structures, something like:

SELECT  s.SNAME, d.QTY
FROM Deliveries d
INNER JOIN Suppliers s
 ON d.s = s.s
INNER JOIN  Products p
 ON d.p = p.p

An unspecified implicit JOIN ie:

SELECT  Suppliers.SNAME, Deliveries.QTY
FROM Suppliers, Deliveries

Will result in every record from each table joining to every record in the other, in your case, 5 records and 12 records = 60 combinations.

于 2013-09-05T20:03:26.270 回答
2

始终使用正确的连接语法。您正在将旧式连接(,where子句中带有条件)与正确的 ANSIjoin语法混合。

你的意思是这样的:

SELECT s.SNAME, d.QTY
FROM Suppliers s join
     Deliveries d
     d.SupplierId = s.SupplierId join
     Products p
     ON d.P = Products.Penter;

我正在弥补 and 之间的连接Suppliers字段Deliveries。而且,我只是猜测那些是需要连接的表(也许是Suppiersand Products)。

于 2013-09-05T20:00:49.083 回答