create table Bug1 ( id_bug1 int(5) unsigned not null auto_increment, section int(5) unsigned not null, primary key(id_bug1) ); insert into Bug1 values(1,1); insert into Bug1 values(2,1); insert into Bug1 values(3,1); insert into Bug1 values(4,2); insert into Bug1 values(5,2); create table Bug2 ( bug2_id_bug1 int(5) unsigned not null, bug2_section int(5) unsigned not null, primary key(bug2_id_bug1,bug2_section) ); insert into Bug2 values(1,2); insert into Bug2 values(2,2); #print out of condition value for all rows: select *, section=1 xor ((not isnull(bug2_section)) and (bug2_section=1)) from Bug1 left join Bug2 on (id_bug1=bug2_id_bug1); #i think MySQL should return rows with id_bug1 1,2, and 3 when I use the same condition in where select * from Bug1 left join Bug2 on (id_bug1=bug2_id_bug1) where section=1 xor ((not isnull(bug2_section)) and (bug2_section=1)); #oops - row with id_bug1=3 is missing #strange workaround - extend condition with "or isnull(id_bug1)" - this always evaluates as false - column id_bug1 is unsigned not null select * from Bug1 left join Bug2 on (id_bug1=bug2_id_bug1) where (section=1 xor ((not isnull(bug2_section)) and (bug2_section=1))) or isnull(id_bug1); #this is ok - this result is what returns MySQL Ver 12.20 Distrib 4.0.13, for pc-linux (i686) for the query without "or isnull(id_bug1)"