I'm new to inner join and left join , Hope somebody can help me with this ..
I have 3 tables ..
- Shirts
- Colors
- Prices
Shirts:
sid | name
------------
01 | Sample1
02 | Sample2
Colors
sid | color | color_id
------------
01 | red | 900
02 | green | 090
Prices:
sid | price
------------
01 | 100
02 | 100
My query is:
SELECT `Shirts`.*, `Colors`.`color`, `Prices`.`price` FROM `Shirts`
INNER JOIN `Colors`
on `Shirts`.`sid` = `Colors`.`sid`
LEFT JOIN `Prices`
on `Shirts`.`sid` = `Prices`.`sid`
WHERE `Shirts`.`sid`='02'
What I would like to achieve is:
sid | name | color | price
----------------------
02 | Sample2 | green | 100
What I get is:
sid | name | color | price
----------------------
null | null | null | null
I know there must be wrong with my query .. So can anyone please tell me what is the right query for that ?