I’m not good at Mysql expressions, so here is a quick question that I’m trying to get my head around. I would like to reverse the order of the GROUP BY expression so that I can get the last entry by the user.
I managed to find good examples around the internet, but I couldn’t implement them with my expression without receiving an error. Thanks guys!
SELECT messages.conv, messages.from_user, messages.to_user,
messages.content, messages.date_posted, messages.note_read,
messages.active, users.thumb, users.name, users.id
FROM `messages`
INNER JOIN `users`
ON messages.from_user = users.id
WHERE messages.from_user = 1
OR messages.to_user = 1
GROUP BY messages.conv
ORDER BY date_posted ASC
EDIT: I apparently misunderstood your requirement, your current query will return a pseudo-random row due to your
GROUP BYnot having any aggregates, what you want is the last row for each conversation which would be something more like (assumingmessages, likeusers, has an autoincrementing primary key calledid);SQLFiddle here.