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 Quote 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. Quote 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! Quote 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. Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/244356-join-and-max-value/#findComment-1255535 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.