3

Given the following table my_table :

my_column
------
A
B
C
D

I would like to be able to join on itself but without duplicate pairs like so:

-- SELECT a.*, b.* FROM my_table a JOIN my_table b ON a.my_column <> b.my_column; 
-- something like so but without the duplicate pairs

a.my_column | b.my_column
------------+-----------
A           | B
A           | C
A           | D
B           | C
B           | D
C           | D

How should I tackle this in SQL ?

Dionys
  • 133
  • 1
  • 5

1 Answers1

5
SELECT *
FROM my_table a
JOIN my_table b ON a.my_column < b.my_column
Akina
  • 20,750
  • 2
  • 20
  • 22