SQL Server - INNER JOIN WITH DISTINCT


Answer :

Try this:

select distinct a.FirstName, a.LastName, v.Districtfrom AddTbl a   inner join ValTbl v  on a.LastName = v.LastNameorder by a.FirstName;

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

select distinct a.FirstName, a.LastName, v.Districtfrom AddTbl a, ValTbl vwhere a.LastName = v.LastNameorder by a.FirstName;

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.Districtfrom AddTbl a inner join (select distinct LastName, District     from ValTbl) v   on a.LastName = v.LastNameorder by Firstname   

Belum ada Komentar untuk "SQL Server - INNER JOIN WITH DISTINCT"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel