Sort select by date

Asked

Viewed 132 times

0

How to sort this select by DATE?

(SELECT * FROM mensagens WHERE de = '2' && para = '1' ORDER BY data)
UNION
(SELECT * FROM mensagens WHERE de = '1' && para = '2' ORDER BY data)

Testing: http://sqlfiddle.com/#! 9/b471a/1

  • No longer ordering by date?

  • @Andersoncarloswoss Ta não.

  • 1

    It is, but you are ordering the two queries before uniting them. Try first to do the union and then sort by the date.

  • @Andersoncarloswoss updated this link to see http://sqlfiddle.com/#! 9/b471a/1

  • I just didn’t understand why you didn’t leave your query like this: SELECT * FROM messages WHERE (from = '2' AND to = '1') OR (from = '1' AND to = '2') ORDER BY data

1 answer

4


(SELECT * FROM mensagens WHERE de = '2' && para = '1')
UNION
(SELECT * FROM mensagens WHERE de = '1' && para = '2')
order by data
  • Thank you Jovani.

Browser other questions tagged

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