Click to See Complete Forum and Search --> : SQL question


makhlo
03-31-2007, 03:27 PM
Hey everybody,

I am new to sql and have a problem to find the solution for this exercise: Find out the makers that sale PCs but not laptops.

The database scheme consists of four relations:

Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)

My own query:

select distinct maker from product, pc
where product.model = pc.model
and type in('pc','printer')

The problem is that i also get the makers who sells pc and laptops.

Thnx for any help,

jasonahoule
03-31-2007, 05:02 PM
Try this:

SELECT DISTINCT maker
FROM product
WHERE product.model IN
(SELECT pc.model
FROM pc);

makhlo
04-01-2007, 06:38 AM
I tried the query you made:

SELECT DISTINCT maker
FROM product
WHERE product.model IN
(SELECT pc.model
FROM pc);

but still get the makers who sell pc and laptops. there must be a solution to filter this makers.

Thnx for you're reply

jasonahoule
04-01-2007, 11:01 AM
Sorry, misunderstood what you were saying. Try something like this:

SELECT DISTINCT maker
FROM product
WHERE maker NOT IN
(SELECT maker
FROM product, laptop, printer
WHERE product.model = laptop.model
AND product.model = printer.model);