0

I have a message system on my site and I would like to see a list of users who sent me a message while displaying only the last message of each user. Same way as facebook.

So, I have a table with the IDUSERSENDER, IDUSERRECEIVER, DATE AND MESSAGE

I tried on several time to take a query but I can not have the last message of each.

Idea?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Stephen
  • 13
  • 3

2 Answers2

0

This easy query should work:

SELECT * FROM messages WHERE receiver = 2 GROUP BY sender ORDER BY date DESC LIMIT 1
Richard
  • 2,840
  • 3
  • 25
  • 37
0

ok, again, try this please

SELECT MESSAGE FROM MY_TABLE WHERE IDUSERRECEIVER = 'MY_ID' AND DATE IN (SELECT MAX(DATE) FROM MY_TABLE GROUP BY IDUSERSENDER); 
Isaac
  • 465
  • 4
  • 11