webguy262 Posted August 9, 2011 Share Posted August 9, 2011 user is in table1, logindate is in table2, userid is common to both tables. need a query that returns the userid, user, and ONLY THE MOST RECENT logindate for each user. i know i need a subselect and a MAX(), but i can't get exactly what i need closest i've come is getting a single result: the userid, user and logindate for the user with the most recent lastlogin appreciate your help Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/ Share on other sites More sharing options...
fenway Posted August 9, 2011 Share Posted August 9, 2011 Post the query you have so far. Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/#findComment-1255069 Share on other sites More sharing options...
webguy262 Posted August 9, 2011 Author Share Posted August 9, 2011 thanks, but i just figured it out! Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/#findComment-1255082 Share on other sites More sharing options...
fenway Posted August 10, 2011 Share Posted August 10, 2011 thanks, but i just figured it out! Then post what you figured out -- other people will benefit from your experience. Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/#findComment-1255249 Share on other sites More sharing options...
webguy262 Posted August 10, 2011 Author Share Posted August 10, 2011 This did what I needed without a subselect... SELECT t1.user, MAX(t2.logindate) FROM t1 LEFT OUTER JOIN t2 l ON t1.user = t2.user GROUP BY user ORDER BY logindate DESC ...key was GROUP BY Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/#findComment-1255535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.