Query records' combinations

Discussion in 'Programming' started by curlito, Oct 16, 2006.

  1. #1
    What I need to do is to get all the combinations of the records from a query.

    Let's say that my query gives me the records: 1,2,3,4

    I need to also get these:

    1,2,3
    1,2,4
    1,3,4
    2,3,4

    AND

    1,2
    1,3
    1,4
    2,3
    2,4
    3,4

    This is for a betting application and when the player chooses 4 games or more I need to calculate the odds for the combinations of 3 matches and 2 matches...

    I hope that's clear enough.

    Thanks all in advance. :)
     
    curlito, Oct 16, 2006 IP
  2. websiteideas

    websiteideas Well-Known Member

    Messages:
    1,406
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Can you show us the exact sql query you're using?
     
    websiteideas, Oct 16, 2006 IP
  3. curlito

    curlito Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it's just a SELECT query:

    SELECT id
    FROM myTable
    WHERE id <= x;

    and the results are:
    1
    2
    3
    4
    .
    .
    x

    and what i need is the combinations of (x-1), (x-2), ..., 2

    Is that more clear?? :confused:
     
    curlito, Oct 18, 2006 IP