pluginbaby Posted July 7, 2007 Share Posted July 7, 2007 hi I want to select the record out of a table with the highest time (MAX(time)) and I want to get the username from that record. This should only be records where ctId=0. I first tried: SELECT MAX(time),username FROM table WHERE ctId=0 but that gave me a grouping error then I did some research about groups and stuff, since I didn't know that much about them, and I tried: SELECT max(time),username,ctId FROM table GROUP BY username,ctId HAVING ctId=0 AND MAX(time) But that gives me not the record with the highest time... :-\ You have any idea what I am doing wrong? Thank you in advance edit: I made a typo in the code Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 7, 2007 Share Posted July 7, 2007 SELECT username,time FROM table WHERE ctID=0 AND time=(SELECT MAX(time) FROM table); Quote Link to comment Share on other sites More sharing options...
pluginbaby Posted July 7, 2007 Author Share Posted July 7, 2007 thanks a lot, it works perfectly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.