The problem is that your subselect is not correlated. In other words, you need to join sp in the main query to supplier in the subquery -- don't join the tables in the subquery. Specifically, the query should be:
SELECT *
FROM sp
WHERE NOT EXISTS (
SELECT 1
FROM supplier -- note SP doesn't appear here!
WHERE supplier.num = sp.num -- sp is from main query
)
I wrote the same thing in my reply below, but didn't point it out specifically.
|