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 Link to comment https://forums.phpfreaks.com/topic/58853-solved-grouping-problem/ 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); Link to comment https://forums.phpfreaks.com/topic/58853-solved-grouping-problem/#findComment-292035 Share on other sites More sharing options...
pluginbaby Posted July 7, 2007 Author Share Posted July 7, 2007 thanks a lot, it works perfectly Link to comment https://forums.phpfreaks.com/topic/58853-solved-grouping-problem/#findComment-292037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.