Any SQL / math ninja's on the green fancy a quick challenge..? So I've got this table containing number pairs, right, and I need to compute all the possible combinations.
For example: I have the following pairs: {1,2}, {1,3}, {3,4}, {2,5}
The implementation I need will produce the following combinations: {1,2}, {1,3}, {3,4}, {2, 5}, {1,3,4}, {1,2,3}, {1,2,5}, {1,2,3,5}, {1,2,3,4}, {1,2,3,4,5}
But not these: {1,4}, {1,5}, {3,5}, {1,2,4}, {1,3,5}
I know, I know, sounds like homework filter but I can assure you it's not - I'm building a shopping cart app thing on LAMP and I can't quite see a clear way around this conundrum. I mean, it could be done recursively in PHP but thats going to involve a) lots of connections / queries to the database, and b) the kind of headaches that only recursion can induce.
Can you see a way of doing this in SQL? Or even an algo which won't hammer the DB server with zillions of l'il queries?
posted by whoojemaflip to computers & internet (25 comments total)
3 users marked this as a favorite
How is (1,2,3,4,5) valid?
I think the answer will be that you're not storing you data correctly, though.
posted by Leon at 4:32 AM on August 15, 2007