The key to what you want to do is to move the condition on the stock to the on
clause from the where
clause. Presumably, your existing query looks something like this:
select <whatever>
from appointments a left join
sells s
on a.appointmentid = s.appointmentid
where s.instock = 1;
The where
clause is turning the left join
into an inner join
. When there is no match, the value of instock
is NULL
, which does not match 1
. The solution is to move the condition to the on
clause:
select <whatever>
from appointments a left join
sells s
on a.appointmentid = s.appointmentid and
s.instock = 1;