Home Forums SQL Server 2008 T-SQL (SS2K8) Recursive cross join to get all available combinaisons RE: Recursive cross join to get all available combinaisons

  • Think of it this way...

    You have 4 persons in a room, how many different "couples" can do a handshake.

    p1 can shake hands with p2,p3,p4

    p2 can't shake hands again with p1 so only p2 with p3 and p4 remain

    then only p3 can shake hands with p4.

    Now that you have that done, how many 3 way hand shaking can you have (this is where recursion kicks in)?

    p1,p2,p3

    p1,p2,p4

    p2,p3,p4

    In my current solution I'm already adressing the possibilities that a single hand shake or everybody at the same time will resolve the join. Now I need everything in between.

    Again I have cases with as much as 16 peoples in the room (16 shippings for 1 single order). So that's 14 levels of recursions to build all possible groups of handshakes. I wish I could give you a formula but I just can't figure that one out atm!!!