BrownChiLD
BrownChiLD

Reputation: 3713

Mysql: order a table using 2 columns in Descending order

i'm a bit stomped..

I'm trying to achieve a fairly simple logic..

I have a "user_sessions" table with log_in and log_out (int, epoch time stamps)

   userID | log_in | log_out

trying to show the RECENT activities, I need to list all the sessions in DESCENDING ORDER based on the LATEST ACTIVITY, and this could either be log_in or log_out.. and this is where i'm stomped. I tried different ORDER and SORT methods... I'm just not getting it.

Upvotes: 0

Views: 44

Answers (1)

Barmar
Barmar

Reputation: 781004

SELECT *
FROM user_sessions
ORDER BY GREATEST(log_in, log_out) DESC

Upvotes: 2

Related Questions