简体   繁体   中英

left join more than one table

essentially I want to left join 3 tables I have joined 2 tables below

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

I have already successfully joined Shop_id i and Shopper s I want to add Clients c to the mix I thought-

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

I was wrong - Help please

you need to explicitly specify the keyword LEFT JOIN for the table 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

can you try like this?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM