Solved

Finding Duplicate Records

Posted on 2002-07-24
4
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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