I have a database like this:
-------------------------------------------------------------------
| id_one | id_two | timestamp_one | timestamp_
SELECT id_one, id_two, timestamp_one, timestamp_two
FROM tablename
WHERE id_one = 27
OR id_two = 27
ORDER BY
CASE
WHEN id_one=27 THEN timestamp_one
WHEN id_two=27 THEN timestamp_two
END DESC
SELECT * FROM tablename
WHERE id_one=27 OR id_two=27
ORDER BY id ASC, timestamp_one DESC
SELECT
id_one,
id_two,
(CASE
WHEN id_one=27 THEN timestamp_one
WHEN id_two=27 THEN timestamp_two
END) as timestamp
FROM tablename
ORDER BY timestamp DESC