Skip to content

Instantly share code, notes, and snippets.

@doryokujin
Created April 23, 2015 03:12
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 doryokujin/fc0cf454f3aa45ccd4e2 to your computer and use it in GitHub Desktop.
Save doryokujin/fc0cf454f3aa45ccd4e2 to your computer and use it in GitHub Desktop.
SELECT n1.id, n2.id, n1.id || ' ♥ ' || n2.id
FROM
(
SELECT id, gender
FROM men_and_women
) n1
JOIN
(
SELECT id, gender
FROM men_and_women
) n2
ON n1.gender != n2.gender
HAVING n1.id < n2.id
ORDER BY n1.id, n2.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment