Solved

Finding Duplicate Records

Posted on 2002-07-24
4
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
Your code didn't work for me.
0
 

Author Comment

by:bhlang
Comment Utility
This code worked exactly as I wanted.
Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

16 Experts available now in Live!

Get 1:1 Help Now