加入不适用于MY SQL

时间:2015-06-19 14:29:54

标签: mysql

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';

1 个答案:

答案 0 :(得分:2)

我非常有信心JOIN是"工作"在MySQL中。

(我可以在这里添加一个示例,证明它有效。)

修改

如果您有两个或多列"共同"在两个表之间,并且您希望在连接谓词中的相等比较中引用这两列,只需将AND col2 = col2添加到现有的ON子句中......

例如,添加cust_idcustomer之间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> customerorders上的customer_numcust_id之间加入,可以替换ANDOR。 (但这是一个奇怪的模式,有两个不同的列匹配;这不是规范模式。)