I'm having problems with my query, basically what I'm trying to do here is to order first by
item_info.content_time desc
and then by
item_views.views desc
My intention is to get the most recent items (order by item_info.content_time desc), with the most views (item_views.views desc). In essence something like the stackoverflow main page, where you have the most recent with the most views (I really don't know if that's how they are doing it). The following query either orders the items by one criteria or the other (if I reverse the order by criteria). Here's my code:
SELECT item_info.item_id, item_info.profile_id, item_info.tittle, item_covers.reference, usuarios.username, item_views.views
FROM item_info
LEFT JOIN item_covers ON item_covers.cover_id = item_info.book_id
LEFT JOIN usuarios ON item_info.profile_id = usuarios.id
LEFT JOIN item_views ON item_views.id = item_info.book_id
WHERE item_info.content_time
BETWEEN UNIX_TIMESTAMP( CURDATE( ) + INTERVAL -1
DAY )
AND UNIX_TIMESTAMP( CURDATE( ) + INTERVAL 1
DAY )
order by item_info.content_time desc, item_views.views desc
Roughly something like...
Expected output:
content_time | views
17:00 500
13:00 300
11:00 100
10:00 50
Actual output:
content_time | views
17:00 500
16:00 10
15:00 30
14:00 50