0
votes

Let's say I have a table with with one column made up of 4 rows.

Names

name1

name2

name3

name4

How could I get all permutations of this column rows. ie

name1 name2 name3 name4

name1 name2 name4 name3

ETC.

2
what sql engine is it? SQL Server, Oracle etc...kevchadders
When you have gotten a solution to your question, mark the correct answer as accepted, and please leave the question intact for others to see.JamesMLV

2 Answers

1
votes

join it to itself?

select t1.name, t2.name, t3.name, t4.name
from table t1, table t2, table t3, table t4
1
votes
select t1.name, t2.name, t3.name, t4.name 
from mytable t1
join mytable t2 on t2.name not in (t1.name)
join mytable t3 on t3.name not in (t1.name, t2.name)
join mytable t4 on t4.name not in (t1.name, t2.name, t3.name)