This is my SQL:
"SELECT users.username, users.id_user, friends.name, friends.meet_date
FROM users INNER JOIN friends ON (users.id_user = friends.id_user)
GROUP BY username ORDER BY username";
This is the output on my webpage:
Username Friend's Name Meeting Date
George Nicolas 2010
Man Anatol 2008
For now, it selects just the first rows from database for each user.
Each table has an auto_increment, id_user for the first table and id_friend for the second one.
I would like it to show that friend which were meet last by each user.
I’ve tried to add an order by "meet_date DESC" but it doesn’t work.
How could I achieve my wish?
The easy way is a subquery:
* Testing *
Results:
Try it at sql fiddle.
Notice thant a correlated subquery is not an elegant approach, is the easy approach.