Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Finding Duplicate Records

Posted on 2002-07-24
4
Medium Priority
?
260 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 400 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

618 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