I have two tables ‘Comments’ and ‘Likes’ and I can show all the comments that have been liked and order them by when the comments where added. What I can’t seem to do at the moment is order the comments according to when they were liked.
This is what I have at the moment:
SELECT *
FROM comments AS c
WHERE EXISTS (
SELECT *
FROM likes AS l
WHERE c.commentID=l.commentID)
Could anyone help me with the SQL to show the comments in order with the one that was most recently liked first and so on…
Just to add – I only want to show the comment once and avoid showing any comments that have not been liked.
If you have multiple likes for a given comment, then you need an aggregation, such as: