SELECT imageId FROM( SELECT imageId,COUNT(imageId) likeCount FROM likes GROUP BY imageId ORDER BY likeCount DESC) c;
SELECT * FROM image WHERE id IN(SELECT DISTINCT imageId FROM likes) ;
SELECT * FROM image;
SELECT imageId, COUNT(imageId) likeCount FROM likes GROUP BY imageId;
SELECT i.*
FROM image i INNER JOIN (SELECT imageId, COUNT(imageId) likeCount FROM likes GROUP BY imageId) c
on i.id=c.imageId
ORDER BY likeCount DESC;
https://easyupclass.e-itwill.com/course/course_view.jsp?id=27&cid=28