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.
join it to itself?
select t1.name, t2.name, t3.name, t4.name
from table t1, table t2, table t3, table t4
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)
精彩评论