I have the following table:
ID | NUM
1 | 4
2 | 9
3 | 1
4 | 7
5 | 10
I want a result of:
ID | NUM
5 | 10
When I try to use MAX(NUM) I get and error that I have to use GROUP BY in order to use MAX function
Any idea?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As per the error, use of an aggregate like
Maxrequires aGroup Byclause if there are any non-aggregated columns in the select list (In your case, you are trying to find theMAX(Num)and then return the value(s) associated in theIDcolumn). In MS SQL Server you can get what you want via ordering and limiting the returned rows:In other RDBMS systems the
LIMIToffers similar functionality.Edit
If you need to return all rows which have the same maximum, then use the
WITH TIESqualification: