Alec Smart Alec Smart - 2 months ago 21
MySQL Question

Left Join Issue

Am trying to do a left join along with a condition. Say this is my table:

a b c
-------------------------
1 1 NULL
3 3 something


and my query is

select * from x left join y on x.a = y.b


The problem is that I don't want c to be "something" so when i add

select * from x left join y on x.a = y.b where y.c <> 'something'


it displays 0 rows. it should actually display

a b c
-------------------------
1 1 NULL

Answer
select * 
from x left join y on x.a = y.b 
WHERE y.c IS NULL OR y.c <> 'something'
Comments