This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM blog.POSTS p | |
LEFT JOIN BLOG.POST_VOTES pv | |
ON p.POST_ID = pv.POST_ID | |
JOIN (SELECT p2.POST_ID as id, COUNT(pv2.VOTE_ID) "count" FROM BLOG.POSTS p2 LEFT | |
JOIN BLOG.POST_VOTES pv2 ON p2.POST_ID = pv2.POST_ID GROUP BY p2.POST_ID) r | |
ON p.POST_ID = r.id ORDER BY r."count"; |