I have a table of values:
+-----+-------+
| ID | STATE |
+-----+-------+
| 1 | AL |
| 1 | AZ |
| 1 | MI |
| 2 | TX |
| 2 | TN |
| 2 | MO |
| 2 | ND |
And many, many more...
How do I write a query that generates all of the possible state combinations for each individual ID? So the results are like:
+-----+-------------+
| ID | COMBINATION |
+-----+-------------+
| 1 | AL, AZ |
| 1 | AL, MI |
| 1 | AZ, MI |
| 1 | AL, AZ, MI |
| 2 | TX, TN |
| 2 | TX, MO |
| 2 | TX, ND |
| 2 | TN, MO |
| 2 | TN, ND |
And so on...
Thanks for the help!
EDIT: Ravshan got me thinking that I do not want permutations but, bonus if the combination string is in alphabetical order.