Log in

View Full Version : Max function using where option



hemi519
07-22-2011, 05:23 AM
Hi All,

I am writing a query where i can get the maximum Id and its name. So iam using this option Max. But this is giving me error.


SELECT Id,Name FROM `User` WHERE Id = Max(Id);

When i submit this query iam getting error

Invalid use of group function

After this i also want query for my second largest Id i am having. Anyone help me in this issue

djr33
07-23-2011, 01:35 AM
Have you tried something like MAX(colname.ID)? It might be using ID as the same as the current entry and having a "max" of a single value doesn't mean anything (or its irrelevant if so). Just a thought. I'm not sure about this.