Select from all users with only one result from each user

Asked

Viewed 113 times

0

Hey, good night, man. I think the title is a little fuzzy, I’ll try to explain better.

I’m making a chat system and I want to list all user conversations, but only one message from each user.

Example:inserir a descrição da imagem aqui It’s showing all the user messages Matthew, but wanted to show only one.

My comic: inserir a descrição da imagem aqui

My select

SELECT * FROM pw_chat ORDER BY data ASC
  • If you want the latest one, better specify it in the question. The current answer given below takes one of each, but does not guarantee that it is the newest one.

1 answer

2


  • Friend format your code for easy reading of it. Learn more about formatting...

  • I just think it should be DESC. since he wants the latest post

  • You should trade the ASC for DESC

  • Another acquired experience, thank you very much. to all :D

  • 1

    CAUTION: This does not guarantee the latest. It depends on DB. The grouping functions do not necessarily respect ORDER. ORDER is applied after grouping in many Engines. Sqlite, for example, makes it clear that it only guarantees if you use a MAX( id ) or something like that. Mysql warns in the manual that this is a side effect and can change at any time.

  • Roughly what is explained here https://answall.com/questions/175280/

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.