AlphaPress Publishing
P.O. Box 5942 Albany, NY 12205
Tel: 518-250-3890
Email: alphapress@hotmail.com 


  

Section Menu 

Are you a University or College bookstore and want to order multiple books?  Email us at alphapress@hotmail.com or call us at 518-250-3890.  We will be happy to talk to you.  

Are you a professor and you need a sample copy?  We will be happy to send you a pdf or printed copy!  Email us at alphapress@hotmail.com.

Are you outside the United States?  We can ship multiple books worldwide in most countries.

  

 

 

Find duplicate records in a table based on the values of one field

To contact the author click here

This article is from the book "Access 2007 Pure SQL

To download the sample database click here


 

Find duplicate records in a table based on the values of one field

Find duplicate customer orders based on the value of the orderID

Discussion:

In this example, we are looking for records in the tbls_Orders table that have the same value for the OrderID field.  In addition, we use the count(*) function to  calculate the number of instances of duplicate records.  We can use the code below to look for duplicate values for any field.  We will just replace the OrderID field with the field on which we want to search for duplicate values.  Remember that this example will give us duplicate field values and not necessarily duplicate records.  Though the OrderID values are the same, the rest of the fields in the returned records might have different values.  Still, it is very useful to know how to search for duplicate values on one field.  As you can see from the result set, two records have null values for the OrderID.  In addition, there are two instances of duplicate records for OrderIDs with values 8, 45, 254, and 820.  Finally, the OrderId with value 993 appears in three records in the table. 

Code:

SELECT OrderID, Count(*) AS NumberofDuplicates

FROM tbls_Orders

GROUP BY OrderID

HAVING count(*)>1
 

Result: