In standard SQL, I want to generate all the various permutations that contain a unique set. For example, how to generate unique band line-ups based on a list of band members and their role. Each lineup must contain each role once
So, given this:
role |name
-------|--------
singer |dave
singer |sammy
guitar |eddie
bass |anthony
bass |wolfgang
drummer|alex
the result would be this with four possible line-ups:
role |name |lineup
-------|--------|-------
singer |dave |1
singer |dave |2
singer |sammy |3
singer |sammy |4
guitar |eddie |1
guitar |eddie |2
guitar |eddie |3
guitar |eddie |4
bass |anthony |1
bass |anthony |3
bass |wolfgang|2
bass |wolfgang|4
drummer|alex |1
drummer|alex |2
drummer|alex |3
drummer|alex |4
The actually use case requires the role column to be flexible. So, we can include keyboard, voilin players and then lineups would have that role.
I am testing out solutions with SQLite using cross-joins and running out of ideas. Seems like a common scheduling sort of problem. Any ideas?
Just to clarify, the result would have every combination possible. So if you run this SQLite query on the result above:
select distinct group_concat(name) combination from result group by lineup
you get four unique records
combination
-------------------------
dave,eddie,wolfgang,alex
dave,eddie,anthony,alex
sammy,eddie,wolfgang,alex
sammy,eddie,anthony,alex
