LEFT OUTER JOIN (gives extra rows) problem

后端 未结 5 2006
梦如初夏
梦如初夏 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:24

    Hmm, the query is doing what its supposed to since there are duplicate records (or at least duplicate identifiers) in the right hand table.

    To get the effect you want something like:

    SELECT * FROM @tb1 LEFT OUTER JOIN (SELECT DISTINCT c2 FROM @tb2) t2 ON @tb1.c1 = t2.c2
    

    If that isn't sufficient you'll need to explain the requirement in a bit more detail.

提交回复
热议问题