September 20, 2015 at 10:34 pm
Does anyone know how to retrieve all possible sets of values from a table, with each set having a unique identifier.
Here's sample data, where any number of rows can be in the "animal" set:
select animal.name
from (
select 'Cat' as name
union all select 'Dog'
union all select 'Bird'
) animal
Here's what I'm trying to get:
SET# NAME
1, Cat
1, Dog
1, Bird
2, Cat
2, Dog
3, Dog
4, Cat
4, Bird
5, Cat
6, Dog
6, Bird
7, Bird
It'd be an easy task if I knew how many rows were in the set, but without knowing how many (and being able to do x number of cross joins and CUBE/ROLLUP to produce the list of permutations) or writing a horrid complex of while loops, I'm at a loss.
Does anyone have any suggestions on how I could do this?
EDIT: A single column. All permutations of the values in a single column. Perhaps I should stay off here nearer the end of the day :Whistling:.
September 20, 2015 at 11:39 pm
September 21, 2015 at 12:21 am
Here it is again in clickable form
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply