Skip to content

Instantly share code, notes, and snippets.

@YanTheFawn
Created March 26, 2014 19:02
Show Gist options
  • Save YanTheFawn/9790803 to your computer and use it in GitHub Desktop.
Save YanTheFawn/9790803 to your computer and use it in GitHub Desktop.
SELECT ordered_posts.vote_score as vote_score,(CASE WHEN current_user_subscriptions.user_id IS NULL THEN '0' ELSE '1' END) as user_is_following, ordered_posts.influencer_id, current_user_subscriptions.user_id
FROM (SELECT * FROM posts ORDER BY vote_score desc) as ordered_posts
LEFT OUTER JOIN
(SELECT * FROM influencer_subscriptions WHERE user_id = 1) AS current_user_subscriptions
ON ordered_posts.influencer_id = current_user_subscriptions.influencer_id
WHERE ordered_posts.community_board = TRUE
GROUP BY influencer_id
ORDER BY user_is_following desc, ordered_posts.created_at desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment