Interesting SQL quiz

sql

Solution

Try this

Select A.Color, B.Color
From Colors A
Cross Join Colors B
Where A.Color > B.Color

Problem

Recently I came across with the following quiz. Imagine we have this table ``` +--------+ | colors | +--------+ | red | | black | | white | | green | | orange | +--------+ ``` The task is to write a SQL query that will select all pairs without allowing duplicates. Permutations are counted too ({red, black} = {black, red}, hence only one of the pair is allowed).

Original source