question

bsanga avatar image
bsanga asked

Algorithm to return all combinations of k elements from n

Can some one please help me to write a function which returns all possible combinations? Ex: if I have 5 elements { 1, 2, 3, 4, 5 } and I want 3 letter combinations..which will result as 123 124 125 134 135 145 234 235 245 345
sqlalgorithm
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
ThomasRushton avatar image
ThomasRushton answered
This is very similar to a [question that was asked here][1] recently. ish. I suggested the OP then have a look at the [non-Phil Factor Speed Phreak][2] competition. And @Kevin Feasel suggested a look at [Paul White's answer to a similar question on http://DBA.StackExchange.Com][3] [1]: http://ask.sqlservercentral.com/questions/96364/sql-query-permutations-without-repetition.html [2]: http://ask.sqlservercentral.com/questions/3045/the-word-permutation-sql-problem.html [3]: http://dba.stackexchange.com/questions/29661/sql-query-for-combinations-without-repetition/29666#29666
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.