Skip to content

Instantly share code, notes, and snippets.

@folkengine
Created December 23, 2011 13:21
Show Gist options
  • Save folkengine/1514196 to your computer and use it in GitHub Desktop.
Save folkengine/1514196 to your computer and use it in GitHub Desktop.
SQL count plus distinct
SELECT
DISTINCT thing1, (select count(B.thing1) from table1 B where A.thing1 = B.thing1) as mycount
FROM
table1 A
INNER JOIN
table2 E on A.table2s_id = e.table2_id
WHERE
( e.bool = 0 )
GROUP BY
A.thing1
ORDER BY
mycount DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment