combinations (not permutations) from cross join in sql

前端 未结 1 757
别跟我提以往
别跟我提以往 2020-12-01 14:11

If I have a table that I\'d like to cross join to itself, how can I remove the duplicate rows? Or to put it another way, how can I do a \"order doesn\'t matter\" cross join?

相关标签:
1条回答
  • 2020-12-01 14:50
    T as t1
    inner join
    T as t2
      on t1.field < t2.field
    

    FWIW, you can just use INNER JOIN for this, it's not strictly a CROSS JOIN. MySQL (and perhaps some other RDBMS) treats these two types of join as identical, but in ANSI SQL, a cross join has no join condition -- it's a deliberate Cartesian product.

    0 讨论(0)
提交回复
热议问题