-1

I want to sort a table having 3 columns (time, source , recipient) by the order by which communication is being made. If the source and recipient are conversing together then it will list them by the time. The goal is to see the communication happening between similar people ordered by time.An example is as:

time|source|recipient

1   paul    amy
2   amy     paul
3   amy     paul
5   paul    jane
8   amy     paul
9   jane    paul
10  paul    amy
11  paul    jane

the end result would be like

1   paul    amy
2   amy     paul
3   amy     paul
8   amy     paul
10  paul    amy
5   paul    jane
9   jane    paul
11  paul    jane
Louis
  • 3
  • 2

1 Answers1

1

Your question is a bit vague. My educated guess is you want this:

SELECT *
FROM   tbl
ORDER  BY (GREATEST(source, recipient), LEAST(source, recipient), "time";

The manual about GREATEST and LEAST.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • Thank you very much Erwin, this solution is exactly what i required. I get the resulting communication between both parties sorted properly by similar source,recipient and time. – Louis Mar 04 '15 at 19:09