Your query returns NULL
because the subquery returns at least one row. Hence something exists. Juergen's answer shows how to do what you want with a left join
. Here is how you solve the problem using not exists
:
select c.category_name
from categories c
where not exists (select 1 from products p where p.category_id = c.category_id);