开发者

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?


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));


Actually you can also use JOIN and using Join depend on what you are going to do.
For example I want to find the maker who produce(s) a PC faster than all laptops and the model of that pc:

SELECT  product.maker , max(product.speed)
From product join pc on product.model = pc.model
Group by product.maker
Having product.speed = max(product.speed)

I think it should work !


Try--

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜