Sunday, October 10, 2010

MySQL cartesian product conditions

Programmer Question

Hi



I need alittle help with a mysql query.
I have 3 tables



x1 x2 x3
1 1 1
2 2 2
2 2 2


and I have 2 joins



select distinct

x1.int1 as a,
x2.int1 as b,
x3.int1 as c

from
x1
JOIN
x2
JOIN
x3


but I would like to generate the cartesian product with the condition that the results
should contain just the just the 3 numbers from x1 (1,2,2) in all orders and I don't know what condition to put in the query



it's a permutation simulation of three elements(1,2,2)
result should be
1,2,2
2,1,2
2,2,1



Thanks



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails