dimanche 10 juillet 2016

How can I order by the newest record from more 1 one table

I have 3 activity for an item. View, Like and Comment. I want to get a list of items according to the latest activity and which activity is done in each item.

I tried to assign a single alias name for mulitple field and use it with order by... But it fails...

How can i achieve this?

SELECT item_name, item_view_date AS date, item_like_date AS date, item_comment_date AS date
FROM item 
LEFT JOIN item_like ON like_item_id = item_id 
LEFT JOIN item_comment ON comment_item_id = item_id 
LEFT JOIN item_view ON view_item_id = item_id 
GROUP BY item_id 
ORDER BY date

Aucun commentaire:

Enregistrer un commentaire