So I've joined two tables for a particular query. After a complicated SELECT statemnt, the table would look vaguely like this: $myid = 3
PostID | FromUserID | To User ID|Date | PostSeen | NumLikes |SeenLike 61 | 48 | 3 | 5/11/13 | 1 | 1 | 1 59 | 3 | 3 | 4/11/13 | 1 | 1 | 0 58 | 3 | 3 | 4/11/13 | 1 | 1 | 1 25 | 47 | 3 | 3/11/13 | 1 | 2 | 0 53 | 56 | 3 | 2/11/13 | 0 | 3 | 1 21 | 3 | 55 | 1/11/13 | 1 | 0 | null 20 | 56 | 3 | 30/10/13| 1 | 0 | null 18 | 47 | 3 | 29/10/13| 0 | 0 | null
If NumLikes is equal to 0 then the SeenLike column is null. The PostSeen will always be 0 or 1. Ive put the date in a simplified format here, but its proper DateTimed.
Essentially, I want do something that is the equivalent of
if(FromUserID == $myid && NumLikes > 0){
ORDER BY SeenLike ASC, Date DESC
}
if (FromUserID != $myid) {
ORDER BY PostSeen ASC, Date DESC
}
(I know this is totally wrong, its just to illustrate vaguely what I'm aiming for) So that it would order the results something like the following:
PostID | FromUserID | To User ID|Date | PostSeen | NumLikes |SeenLike 59 | 3 | 3 | 4/11/13 | 1 | 1 | 0 25 | 47 | 3 | 3/11/13 | 1 | 2 | 0 53 | 56 | 3 | 2/11/13 | 0 | 3 | 1 18 | 47 | 3 | 29/10/13| 0 | 0 | null 61 | 48 | 3 | 5/11/13 | 1 | 1 | 1 58 | 3 | 3 | 4/11/13 | 1 | 1 | 1 21 | 3 | 55 | 1/11/13 | 1 | 0 | null 20 | 56 | 3 | 30/10/13| 1 | 0 | null
How would I go about doing this? I've tried IF's and CASE's but none have worked so far. Would appreciate an explanation to any answer as well! Thanks for any help!