الاثنين، 12 ديسمبر 2011

Find Duplicate Records in SQL Oracle. SQL Server, or Access


Find Duplicate Records in SQL

Oracle. SQL Server, or Access

by Les Smith
Print this ArticleDiscuss in Forums

How can I find duplicate records on a field in a database table?  This works in SQL Server, Oracle, or Access.

Quite often I encounter the need to find duplicate rcords in database tables.  This brief article will return a results set of duplicate records.
In order to find duplicate values in a table, use the following SQL.
SIMPLE:
select distinct employee from employees (nolock)
group by employee
having count(employee) > 1
order by employee


Complex:
select employee, firstname, lastname, dob
from employees (nolock)
where employee in
(select employee from employees (nolock)
group by employee
having count(employee)>1)
order by employee

ليست هناك تعليقات:

إرسال تعليق