左连接多个表

时间:2012-10-20 22:04:46

标签: mysql sql mysqli

基本上我想要加入3个表,我加入了2个表

SELECT  * 
FROM    Shop_id i
        LEFT JOIN Shopper s 
           ON i.shopper_id = s.uid
WHERE   i.shopper_comp > 0 AND 
        i.editor_comp = 0
ORDER BY i.sid

我已成功加入Shop_id i和Shopper s我想将Clients添加到我认为的混合物中

SELECT  * 
FROM    Shop_id i
        LEFT JOIN Shopper s, Clients c 
           ON i.shopper_id = s.uid AND i.cid = c.CID
WHERE   i.shopper_comp > 0 AND 
        i.editor_comp = 0
ORDER BY i.sid

我错了 - 请帮助

2 个答案:

答案 0 :(得分:5)

您需要为表格LEFT JOIN明确指定关键字clients

SELECT * 
FROM   Shop_id i
       LEFT JOIN Shopper s
          ON i.shopper_id = s.uid 
       LEFT JOIN Clients c 
          ON i.cid = c.CID
WHERE  i.shopper_comp > 0 AND 
       i.editor_comp = 0
ORDER BY i.sid

答案 1 :(得分:1)

你能尝试这样吗?

SELECT * FROM Shop_id i
LEFT JOIN Shopper s ON i.shopper_id = s.uid
LEFT JOIN Clients c ON  i.cid = c.CID
WHERE i.shopper_comp >0 AND i.editor_comp =0
ORDER BY i.sid