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
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
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 php mysql mysqli
You are not signed in. Login or sign up in order to post.
No longer ordering by date?
– Woss
@Andersoncarloswoss Ta não.
– Tiago
It is, but you are ordering the two queries before uniting them. Try first to do the
union
and then sort by the date.– Woss
@Andersoncarloswoss updated this link to see http://sqlfiddle.com/#! 9/b471a/1
– Tiago
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
– Marcelo Diniz