Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    5

    Unanswered: cartesian product without repeating pairs inversed

    i have a table with one column, i want to extract all pairs (a,b) where a in table and b in table and if (a,b) is on the result (b,a) must not be extracted ..
    can i do that white an sql request ?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT t1.col AS a, t2.col AS b
      FROM daTable AS t1
    CROSS
      JOIN daTable AS t2
     WHERE t1.col < t2.col
    of course, this only works if the col values are unique, which they would have to be because the table has only one column, so this column has to be the primary key, and therefore unique

    otherwise it's not a table, it's a bag

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2010
    Posts
    5
    Yes, This is it !! Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •