Solved

Finding Duplicate Records

Posted on 2002-07-24
4
252 Views
Last Modified: 2010-05-02
I'm using a Microsoft Access database (not created in Access) in VB6. I need to be able to detect duplicate records using SQL.

Each record has an InvoiceNumber field which is a Long. Each InvoiceNumber should be unique but I don't want to use an Index to make the InvoiceNumber unique. (I didn't design the database, I just have to work with it.)

I want to be able to create a recordset that contains all duplicate InvoiceNumbers in the database.
0
Comment
Question by:bhlang
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
RainUK earned 100 total points
ID: 7175070
Try this SQL Statement :

SELECT InvoiceNumber
FROM tablename
GROUP BY InvoiceNumber
HAVING
count(*) > 1


This will return a recordset of all invoice numbers which have been duplicated in the DB. By the way if you want to make the invoice number a unique, just set it as the Primary Key. This will throw an error if somebody then trys to insert another row with the same invoice number.

But remember to clear the duplicates first, otherwise primary key won't work.
0
 
LVL 5

Expert Comment

by:jayeshshah
ID: 7175229
the sql would be

select InvoiceNumber, count(*) as Duplicatecount from tablename
group by Invoicenumber
where count(*) > 1


this shall return you all the duplicated Invoice Numbers as well as No of time each invoice number has been duplicated
0
 

Author Comment

by:bhlang
ID: 7175247
Your code didn't work for me.
0
 

Author Comment

by:bhlang
ID: 7175248
This code worked exactly as I wanted.
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now