SQL Server - INNER JOIN WITH DISTINCT

后端 未结 6 1172
小蘑菇
小蘑菇 2020-12-16 11:28

I am having a hard time doing the following:

select a.FirstName, a.LastName, v.District
from AddTbl a order by Firstname
inner join (select distinct LastName         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 12:12

    It's not the same doing a select distinct at the beginning because you are wasting all the calculated rows from the result.

    select a.FirstName, a.LastName, v.District
    from AddTbl a order by Firstname
    natural join (select distinct LastName from
                ValTbl v  where a.LastName = v.LastName)
    

    try that.

提交回复
热议问题