SQL Server - INNER JOIN WITH DISTINCT

后端 未结 6 1190
小蘑菇
小蘑菇 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:22

    I think you actually provided a good start for the correct answer right in your question (you just need the correct syntax). I had this exact same problem, and putting DISTINCT in a sub-query was indeed less costly than what other answers here have proposed.

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

提交回复
热议问题