Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB Duplicates

Status
Not open for further replies.

curvv

IS-IT--Management
Jan 11, 2001
103
ZA
Hi,

How can I check for and count the number of duplicates in a Table?

thanx
chris ######## CtN ########
 
Hi

You could do a "select distinct" on your table and compare the number of returned records to the number of records in the table. You could also try a "select ... group by ... having count(field)>1" to give you a list of all records which have duplicates. Derren
[Mediocre talent - spread really thin]
 
sql query to pull dupes and the num:

SELECT COUNT(*), col1
FROM yourTable
GROUP BY col1
HAVING COUNT(*) > 1

Where col1 is the column you want to check for duplicates.

:)
paul
penny1.gif
penny1.gif
 
Hi,

i get asp error:

Error Type:
(0x80020009)
Exception occurred.

my code:

sqlVerQ = "SELECT COUNT(*), Productid FROM product GROUP BY Productid HAVING COUNT(*) > 1"
set rsVer = objConnPr.execute(sqlVerQ)

response.write &quot;Number of Duplicate Records: &quot; & rsVer(0) & &quot;<p>&nbsp;</p>&quot;
######## CtN ########
 
Try plugging that statement directly into your database, and see what it returns.

Also, that doesn't return a &quot;number of duplicate records&quot;.

It returns a dataset with counts and values of your duplicate records. Once you plug it straight into your database, you should see what I'm talking about.
penny1.gif
penny1.gif
 
ok, i understand now what values are being returned from the sql query, but how do i output any of those values?

my query:
SELECT COUNT(*),Category FROM product GROUP BY Category HAVING COUNT(*) > 1

the output i got was two columns:
XPR1000 and Category

with values
6 bla1
6 bla2

how can i now return those values and response.write there are 6 of bla1 and 6 of bla2???

thanx ######## CtN ########
 
don't worry, it works fine now. the reason i got the exception was because i checked the primary key for duplicates which cannot duplicate anyway.

thanx it works fine ######## CtN ########
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top