Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

left join more than one table

Tags:

sql

mysql

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

like image 245
James Stafford Avatar asked Apr 23 '26 13:04

James Stafford


1 Answers

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
like image 63
John Woo Avatar answered Apr 25 '26 04:04

John Woo