开发者

mysql left join if not exist or value equals 0

开发者 https://www.devze.com 2023-02-20 22:58 出处:网络
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 = 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

0

精彩评论

暂无评论...
验证码 换一张
取 消