Reputation: 19
The link of the question is in http://www.sql-ex.ru/learn_exercises.php#answer_ref.
The schema is
The question is to find the makers producing PCs but not laptops.
The query written by me is
select maker
from product, pc
where product.model=pc.model
and maker not in
(
select maker
from product,laptop
where product.model=laptop.model
)
And the message I am getting is
Your query returned the correct dataset on the first (available) database, but it returned incorrect dataset on the second checking database.
Upvotes: 0
Views: 81
Reputation: 50163
You can do join
with not exists
:
select distinct p.maker
from product p inner join
pc
on pc.model = p.model
where not exists (select 1 from laptop l where l.model = p.model);
However, join
will produce duplicate rows if pc
table has duplicate rows. So, you can use exists
instead :
select p.maker
from product p
where exists (select 1 from pc where pc.model = p.model) and
not exists (select 1 from laptop l where l.model = p.model);
Upvotes: 0