Union e order by juntos

Asked

Viewed 64 times

0

Good have in MYSQL database table chatlogs with: from,for,msg,datetime.

Where are the messages exchanged and information ok, starting from this point I would like to know how to make a history of the messages, example:

Carlos logged into his account in Maria’s chat then would retrieve the old conversations again in order by datahr using datetime

Ex:

select msg from chatlogs where de = joana and para = carlos order by datetime ... conseguiria recuperar o historico msgs dela em ordem ... porem preciso que o histórico mostre tudo em ordem minhas msg tambem ... 

Ex:

Joana:hi Carlos: Hey, what’s up? Joana: Yes and you? carlos: td ok

correct order + I don’t know how I would do, had tried so:

select msg from chatlogs where de = joana and para = carlos 
union
select msg from chatlogs where de = carlos and para = joana 
order by datetime

Explanation of what I tried to do: I tried to get all msg sent from Carlos to Joana and all msg from Joana to Carlos and I joined with Union everything and then I had it sent in order by datahr.

Any suggestions?

  • Although I prefer the @Thiagothaison solution below, what you have should work. Which problem gave?

  • opa thanks to attention bfavaretto , then it is because I am unable to test now and as I had needed and a boy said that way it would not work I came to find a solution , it is always good to spare doq missing kkk

1 answer

2

You can get this result by simply changing your select without the need to use union.

select msg from chatlogs where (de = joana and para = carlos) or (de = carlos and para = joana) order by datetime
  • Thank you very much, man, a hug!.

Browser other questions tagged

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