mysql left join if not exist or value equals 0
select a.*, b.status
FROM a
LEFT JOIN b ON a.bid = b.id
WHERE b.status = null or b.开发者_运维百科status=0 # thanks didnt mean to put ==
select a.*, b.status
FROM a LEFT JOIN b ON a.bid = b.id
WHERE b.status < 1
# hoping this would pull 0 and no matches but didnt work either
The above does not work. I am using mysql4.
I need a way to only pull records who are null meaning there is no match or status 0 in table b.
Thanks
IS NULL
is a proper way to compare value with null
(null
= null
evaluates as null
(false)).
select a., b.status FROM a
LEFT JOIN b ON a.bid = b.id WHERE b.status IS NULL or b.status = 0
b.status IS NULL
that should work in your WHERE
clause
精彩评论