Skip to content

Instantly share code, notes, and snippets.

@nicolasiensen
Created August 20, 2012 18:41
Show Gist options
  • Save nicolasiensen/3406551 to your computer and use it in GitHub Desktop.
Save nicolasiensen/3406551 to your computer and use it in GitHub Desktop.
SELECT DISTINCT users.*, (SELECT COUNT(p.*) FROM pokes p WHERE p.user_id = users.id AND p.campaign_id = 3) as pokes_count FROM "users" INNER JOIN "pokes" ON "pokes"."user_id" = "users"."id" WHERE (pokes.campaign_id = 3) ORDER BY RANDOM() LIMIT 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment