Doubt in SQL Query

Asked

Viewed 30 times

1

Guys I have the following table:

--- mensagens
id
usuario_envia
usuario_recebe
texto
data_envio

But I want to list only the "Conversations", for example, I want you to list the messages grouping them with their respective users who sent them.

In consultation SELECT * FROM mensagens ORDER BY id will list all messages, but I want you to list by user you sent. Thank you.

  • SELECT * FROM messages WHERE user_send = "user id" ORDER BY id

  • For example if user A sent two messages pro user B, with this query will list these two messages, I want to list only one message per user that sent

  • got it, I mean on the outside, but I think putting LIMIT 1 should work that way

1 answer

2


SELECT * FROM mensagens GROUP BY usuario_envia
  • Caracas, that’s right, I’m so stressed that I forgot about GROUP BY. Thank you.

Browser other questions tagged

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