SELECT DISTINCT c.fname,
s.description FROM customer c INNER JOIN orders o ON c.customer_num =
o.customer_num INNER JOIN items i ON o.order_num = i.order_num INNER
JOIN stock s on s.stock_num = i.stock_num WHERE i.manu_code = 'ANZ';
答案 0 :(得分:2)
我非常有信心JOIN
是"工作"在MySQL中。
(我可以在这里添加一个示例,证明它有效。)
修改强>
如果您有两个或多列"共同"在两个表之间,并且您希望在连接谓词中的相等比较中引用这两列,只需将AND col2 = col2
添加到现有的ON
子句中......
例如,添加cust_id
与customer
之间orders
相等的条件
SELECT DISTINCT c.fname
, s.description
FROM customer c
JOIN orders o
ON o.customer_num = c.customer_num
AND o.cust_id = c.cust_id
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ add this line
JOIN items i
ON i.order_num = o.order_num
JOIN stock s
ON s.stock_num = i.stock_num
WHERE i.manu_code = 'ANZ';
如果您想在 <{em> customer
或orders
上的customer_num
和cust_id
之间加入,可以替换AND
与OR
。 (但这是一个奇怪的模式,有两个不同的列匹配;这不是规范模式。)