您可以JOIN
将表与自身进行比较firstname
,lastname
并DOB
确保它们是相同的值,然后employeeid
是不一样的:
select *
from yourtable t1
inner join yourtable t2
on t1.firstname = t2.firstname
and t1.lastname = t2.lastname
and t1.dob = t2.dob
and t1.empid != t2.empid
上面的查询可能会显示重复的记录,因此您可以使用以下内容(请参阅SQL Fiddle with Demo):
select DISTINCT t1.empid,
t1.firstname,
t1.lastname,
t1.DOB
from yourtable t1
inner join yourtable t2
on t1.firstname = t2.firstname
and t1.lastname = t2.lastname
and t1.dob = t2.dob
and t1.empid != t2.empid
或者您可以使用EXISTS
(参见SQL Fiddle with Demo):
select t1.empid,
t1.firstname,
t1.lastname,
t1.DOB
from yourtable t1
where exists (SELECT *
FROM yourtable t2
WHERE t1.firstname = t2.firstname
and t1.lastname = t2.lastname
and t1.dob = t2.dob
and t1.empid != t2.empid)