James Stafford
James Stafford

Reputation: 1054

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

Upvotes: 3

Views: 5117

Answers (2)

chrome
chrome

Reputation: 659

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

Upvotes: 1

John Woo
John Woo

Reputation: 263683

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

Upvotes: 5

Related Questions