LEFT JOIN query not returning all rows in first table

Move the b condition from WHERE to ON to get a real LEFT JOIN. (With the b condition in the WHERE clause, it executes as a regular inner join…)

select a.id, a.name, b.store, b.stock
from products a left join stock b
  on a.id = b.id and b.store="001"
order by a.id

Leave a Comment