Reputation: 63
Let's say there is a table that contains data rows as below.
As you see above, Applicant 79 has a twin 80 and Twin 80 has Applicant 79 as a twin.
Since ID 11 and 12 are really the same information, I am wishing to select a unique twin data as following.
How can I achieve this in SQL Server?
Thank you very much in advance.
Upvotes: 0
Views: 64
Reputation: 48770
You can simply do:
select * from t where ApplicantId < TwinId
Upvotes: 3
Reputation: 222402
One option uses not exists
select t.*
from mytable t
where not exists (
select 1
from mytable t1
where
t1.applicantid = t.twinid
and t1.twinid = t.applicantid
and t1.applicantid < t.applicantid
)
When mirror records are present, this retains the record with the smallest applicantid
.
Upvotes: 2