Select from all users with only one result of each user [duplicate]

1

Hello, good evening. I think the title is a bit confusing, I'll try to explain it better.

I'm doing a chat system and I'm wanting to list all user conversations, but only one message from each user.

Example: ItisshowingallmessagesfromtheuserMatthew,butIwantedtoshowonlyone.

MyDB:

My select

SELECT * FROM pw_chat ORDER BY data ASC
    
asked by anonymous 23.04.2018 / 06:31

1 answer

2

Very simple, just group by user:

SELECT * FROM pw_chat GROUP BY usuario ORDER BY data DESC

SQLFiddle - Online sample

    
23.04.2018 / 09:49