SQL Server - INNER JOIN WITH DISTINCT

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

    Try this:

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

    Or this (it does the same, but the syntax is different):

    select distinct a.FirstName, a.LastName, v.District
    from AddTbl a, ValTbl v
    where a.LastName = v.LastName
    order by a.FirstName;
    

提交回复
热议问题