this is a bit tough for me to explain, I'm trying to get every possible combination of numbers while only using the numbers all together once, for example, if I have the numbers 1 through 10 and want the unique combinations in groups of 3:
1,2,3
4,5,6
7,8,9
These are fine, but I'm currently doing a Cartesian join on some tables, so for the first group I'm getting:
1,2,3
3,2,1
1,3,2
2,3,1
2,1,3
etc... since I've already used 1,2,3 once, I don't want all the other combinations of it.
This is the code I'm currently using, I'm not quite sure how to do what I want in SQL. The id1,id2,id3 are the 3 numbers I'm trying to find all possible combinations of.
INSERT INTO recipe_index
SELECT distinct '3' as nummeals, t1.id as id1, t2.id as id2, t3.id as id3,
t1.calories+t2.calories+t3.calories as calories, t1.protein+t2.protein+t3.protein as
protein, t1.carbohydrate+t2.carbohydrate+t3.carbohydrate as carbohydrate,
t1.fat+t2.fat+t3.fat as fat from recipes t1, recipes t2, recipes t3
I hope what I'm trying to accomplish here makes some sense..