tags:

views:

28

answers:

2
+1  Q: 

SQL Sub Query Help

I am having trouble with a homework question. Specifically, find the maker(s) who produce(s) a PC faster than all laptops. The query I am using is

SELECT  DISTINCT maker
From Product
Where model = (SELECT model
                        FROM PC 
                        WHERE speed > ALL (SELECT speed
                                             FROM Laptop));

However I keep getting an error saying that my sub query is returning more than one row. Is this a syntax error on my part or is my logic just off?

+1  A: 

Your logic would appear to be off.

This filter clause using a subquery:

Where model = (SELECT model FROM PC WHERE speed > ALL (SELECT speed FROM Laptop));

must return a single row in order for it to work.

You could try:

Where model IN (SELECT model FROM PC WHERE speed > ALL (SELECT speed FROM Laptop));
Mitch Wheat
Thank you so much. I completly forgot that comparison operators only work for a single value. DOH! Thanks for the help, now I'm off to start my PERL homework.
Pinsickle
A: 

Try--

    SELECT  DISTINCT maker 
From Product 
Where model = (SELECT DISTINCT model 
                        FROM PC  
                        WHERE speed > (SELECT MAX(speed) 
                                             FROM Laptop)); 
James Anderson
Thanks for the suggestion. However I frogot to mention that we are not allowed to use max, min, avg etc for this homework
Pinsickle