Skip to Content
0

Whats wrong in this query in SQLScript

Jan 09, 2017 at 03:40 PM

74

avatar image

Hi,

I want to know Name and city of person (owner) who is having the car with maximum horse power (HP). I'm writing below query for this:

SELECT OWNERID FROM "CLF01"."CAR" WHERE OWNERID = (

SELECT TOP 1 OWNERID, MAX(HP) FROM "CLF01"."CAR" GROUP BY OWNERID ORDER BY 2 DESC );

its giving me error 'too many values'. Inner query is working fine and giving me Ownerid with maximum HP.

Could anybody please help me on this.

Thank you

10 |10000 characters needed characters left characters exceeded

Sorry ! posted wrong query in above post. My query goes like below:

SELECT NAME CITY FROM "CLF01"."CAR" WHERE OWNERID = (

SELECT TOP 1 OWNERID, MAX(HP) FROM "CLF01"."CAR" GROUP BY OWNERID ORDER BY 2 DESC );

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Jan 10, 2017 at 07:16 AM
0

If you need only the owner(s) with a car with the max. available horse power in the pool I would go with following statement:

SELECT "NAME", "CITY" FROM "CLF01"."CAR" WHERE "HP" = (SELECT MAX("HP") FROM "CLF01"."CAR");
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thats correct ! Thanks Florin. i guess i was over thinking it by using group by and top clause.

0