I'm creating a chat in an android app and need to display this screen: Mydatabaselookslikethis:Messagetable:
I'm making this an example query for the user who has id = 43
SELECT m.dono, m.dest , m.recebido, m.data,
IF(m.dono=43,(SELECT nick FROM usuarios WHERE id=m.dest),(SELECT nick FROM usuarios WHERE id=m.dono)) AS nick,
IF(m.dono=43,(SELECT foto FROM usuarios WHERE id=m.dest),(SELECT foto FROM usuarios WHERE id=m.dono)) AS foto
FROM mensagens as m
WHERE (m.dono = 43 or m.dest=43)
ORDER BY m.data desc
and then in PHP I filter the results and send the pro data to the problem that this query is catching all user chats! imagine when you are 1 year of chat the amount of messages that will process to show just this ... I've already tried to use Group by m.dono + m.dest so it returns missing data: \
I need only the last message sent or received to others I'm getting this:
manda - recebe - data - nick - foto
43 29 0 2017-08-24 20:15:53 rafael sp Sm9zw6kg.jpg
43 29 0 2017-08-24 20:08:53 rafael sp Sm9zw6kg.jpg
43 23 0 2017-08-24 20:05:53 Jose fsdfsdfs.jpg
29 43 0 2017-08-23 10:15:53 rafael sp Sm9zw6kg.jpg
and not just
43 29 0 2017-08-24 20:15:53 rafael sp Sm9zw6kg.jpg
43 23 0 2017-08-24 20:05:53 Jose fsdfsdfs.jpg