jawbreaker Posted January 8, 2007 Share Posted January 8, 2007 Lets say I have two tables NameID Name-------------------1 Joe2 Steve3 Marty4 Doug-------------------ID NameID Last LogIn-------------------------1 1 2006-01-012 1 2006-01-023 2 2006-01-024 3 2006-01-035 4 2006-01-036 4 2006-01-047 1 2006-01-048 2 2006-01-04-------------------------I have joined the tables (on name ID) and now I want to add to the sql statement so that it lists each of the peoples last login and only the last login. I have tried to use GROUP BY but it only gives me the first login and not the last login.I need the output to look like the followingJoe 2006-01-04Steve 2006-01-04Marty 2006-01-03Doug 2006-01-04 Link to comment https://forums.phpfreaks.com/topic/33362-php-mysql-query-question-join/ Share on other sites More sharing options...
fenway Posted January 8, 2007 Share Posted January 8, 2007 You'll need a subquery to find the most recent login, or a derived table with the equivalent (userID,last login) pairs. Link to comment https://forums.phpfreaks.com/topic/33362-php-mysql-query-question-join/#findComment-156074 Share on other sites More sharing options...
sloshire1 Posted January 8, 2007 Share Posted January 8, 2007 It seems far easier just to track the last login rather than keep a record of all the logins for every user. The simplest way out if to as a last login column to the name table, then update it when that user logs in. Link to comment https://forums.phpfreaks.com/topic/33362-php-mysql-query-question-join/#findComment-156131 Share on other sites More sharing options...
fenway Posted January 9, 2007 Share Posted January 9, 2007 Depends what you're trying to do, but yes, summary columns can be useful. Not that such a join is really expensive. Link to comment https://forums.phpfreaks.com/topic/33362-php-mysql-query-question-join/#findComment-156364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.