-2

So I am trying to find those manufacturers that sell Laptops, but not PC’s.

The schemas of the relations provided are: Product (maker, model, type), PC (model, speed, ram, hdisk, price), Laptop (model, speed, ram, hdisk, screen, price), and Printer (model, color, type, price)

I tried:

 (SELECT DISTINCT maker
 FROM Product P
 WHERE P.type=’Laptop’)
 EXCEPT
 (SELECT DISTINCT maker
 FROM Product P
 WHERE P.type=’PC’);

But I get the following error:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXCEPT (SELECT DISTINCT maker FROM Product P WHERE P.type=’PC’)' at line 4

What am I doing wrong here? The EXCEPT in the query is underlined red in MySQL Workbench.

Shadow
  • 33,525
  • 10
  • 51
  • 64

2 Answers2

1

As far as i Know MySQL doesn't support EXCEPT syntax. Try using NOT IN or a LEFT JOIN:

(SELECT DISTINCT maker
FROM Product P
WHERE P.type=’Laptop’)
where marker not in
(SELECT DISTINCT maker
FROM Product P
WHERE P.type=’PC’);
Mohammad
  • 1,549
  • 1
  • 15
  • 27
0

As mentioned by @paul there is no

EXCEPT

in MySQL. Also you don't need the other subquery depending upon your database design.

SELECT DISTINCT maker FROM Product P WHERE P.type=’Laptop’

This will automatically only select product type that are only 'laptop' and not 'PC'. It all depends how efficiently you design your database.

shivgre
  • 1,163
  • 2
  • 13
  • 29