Skip to content

Instantly share code, notes, and snippets.

@jtreher
Created November 13, 2014 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtreher/40131798ee84df6259b4 to your computer and use it in GitHub Desktop.
Save jtreher/40131798ee84df6259b4 to your computer and use it in GitHub Desktop.
SELECT 1 AS ID
INTO #left
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4;
SELECT 1 AS ID
INTO #right
SELECT COUNT(*), tl.total
FROM #left l
left join #right r
on l.id = r.id
cross join
(
SELECT
COUNT(*) as total
, 0 as id
FROM #left
) tl
WHERE r.id IS NULL
GROUP BY tl.total;
DROP TABLE #left;
DROP TABLE #right;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment