I want to left join two tables and then return some of the records.
My first query was:
SELECT * FROM card LEFT OUTER JOIN user_card ON card.id = user_card.card_id WHERE card.package_id =14 AND ( user_card.user_id = '5' OR user_card.user_id IS NULL)
Then when I noticed some problems
(ie result has fewer rows than just
SELECT FROM card WHERE package_id=14)
I wrote this:
SELECT * FROM (select * from card WHERE package_id=14 ) as cc LEFT OUTER JOIN (select * from user_card WHERE user_id=5 ) as uu ON cc.id = uu.card_id
Why these two queries act differently?
How can I do it right without sub-querying ?
P.S : I'm using MySQL, and all
id columns are