MySQL Forums
Forum List  »  PHP

Re: sort Table for pairs
Posted by: Peter Brawley
Date: November 28, 2016 11:10AM

The table is not well designed for the query you want. Is there even a primary key?

Yes, one solution would indeed be to suck the table into PHP and create the desired result by manipulating the arrays in PHP.

In SQL, the pairs who had conversations are ...

select distinct abs as a, emp as b from msgs
union
select distinct emp as a, abs as b from msgs

... so their conversations are ...

select abs, emp, content, date from messages m
join (
  select distinct abs as a, emp as b from messages
  union
  select distinct emp as a, abs as b from messages
) p on (abs=a and emp=b) or (abs=b and emp-a)
order by a,b,date;

Options: ReplyQuote


Subject
Written By
Posted
November 28, 2016 06:37AM
Re: sort Table for pairs
November 28, 2016 11:10AM
November 28, 2016 04:08PM
November 28, 2016 04:55PM
November 28, 2016 08:37PM
November 29, 2016 03:04AM
November 29, 2016 10:01AM
November 29, 2016 01:33PM
November 29, 2016 01:56PM
November 29, 2016 03:23PM
November 29, 2016 03:47PM
November 29, 2016 05:55PM
November 29, 2016 07:26PM
November 30, 2016 06:41AM
November 30, 2016 10:42AM
November 30, 2016 10:48AM
November 28, 2016 08:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.