# fastest way to generate permutations of a table with n columns and put in a new table added one more question to same how to remove duplicate rows

As i am from mathematics background and require to do some huge permutations to start in my work kind help.

If i have a table by name sample1 with n columns what is fastest way to get all the permutations of the rows of sample1 into a new table. n>=12 say.

Please provide kind help with a link where i can get help or any code or query.

An example

say the 6 columns of a row contain

``````E1       E2      E3        E4        E5        E6

'[0,1]' '[1,2]'  '[2,3]'   '[3.4]'   '[4,5]'   '[9,10]'
``````

I need to include its permutations

like

``````E1       E2      E3        E4        E5        E6

'[1,2]' '[0,1]'   '[2,3]'   '[3.4]'   '[4,5]'  '[9,10]'

'[0,1]'   '[2,3]' '[3.4]' '[4,5]'  '[9,10]' '[1,2]'
``````

and other permutations of row 1 above if there are n columns there will be n! permutations i need them also to be generated quickly and put into a new table. U can the headers as column name each is a varchar.

Like for the above table if there are two rows with same elements in each of its columns how to remove duplicates kind help with any query

• What do you mean by "permutations of rows"? Can you provide some example of what you have and what you want to obtain? Commented Dec 18, 2015 at 17:06
• Define "huge". Are we talking a million permutations, a billion permutations, or hundreds of billions of permutations? Commented Dec 18, 2015 at 17:13
• huge may be 5 lac rows and each has to be permuted 12! ways and added to the table Commented Dec 19, 2015 at 3:13
• Kind help with a query to remove duplicate rows Commented Dec 19, 2015 at 15:52
• I'm not sure what you mean by duplicate rows, is `E_i != E_j` if `i != j`? Commented Dec 21, 2015 at 22:20

If those values are in the same order, then a simple `select distinct * from t1` would eliminate the duplicates. If instead the values are in a different order, then you actually have to determine the permutations for each row and make sure only one of those is in the initial table.