LEFT OUTER JOIN (gives extra rows) problem

后端 未结 5 1981
梦如初夏
梦如初夏 2021-01-04 11:02

I have two tables which I want to join together using a left outer join. However, even though my left table contains only unique values, the right table satisfies the CONDI

5条回答
  •  攒了一身酷
    2021-01-04 11:22

    Sorry, but your thinking is skewed.

    Think about it this way: if you only want one single row from tb2 for each row in tb1, which one should the server choose? The fact is that from the definition of a join, every row in the right-hand-side table that matches the left-hand-side row is a match and must be included.

    You'll have to ensure tbl2 has distinct values for c2 before the join. Murph's suggestion might do it, provided your SQL variant supports DISTINCT [column] (not all do).

提交回复
热议问题