Subsribe to our RSS

latest reactions

Dark
I saw more of this staff at http://loadi …
Sean
What about if it isn't in a session, but …
Tjarko
Strange thing however is that the same s …
jax
another option.. replace the path separa …
jax
Load the file into eclipse and turn on ' …

mxna feeds

Error opening the editorColdfusion Tutorial : Hold OutputMore New Adobe Topics - Adam Lehman and Tom JordahlPlease Welcome Rachel Luxemburg to AdobeNew Mango Blog Plugin: Auto PingColdFusion 9 Feature Request: Drop Ajax/JS librariesNew Version of Feed Ping for Mango BlogSite Map Generator: Mango Blog PluginColdFusion Demos v. 2Playing with jQuery - ColdFusionBloggers.org UpdateFree ColdFusion Training by ColdFusion User Group, IndiaHow to change ColdFusion / JRun logging locationSpeakers getting ready for CFUnitedWeb standards awareness among CF developersUsing ColdFusion to create an Encryption / Decryption Key from Plain Text

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2008 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos GallupaPowered by ColdFusion MX 7.01

How to find duplicate values in a table?

With the SQL statement below you can find duplicate values in any table, just change the tablefield into the column you want to search and change the table into the name of the table you need to search.

In your recordset you will see the tablefield and how many times it is found as a duplicate.

SELECT     tablefield, COUNT(tablefield) AS dup_count
FROM         table
GROUP BY tablefield
HAVING     (COUNT(tablefield) > 1)

Some further tempering with the statement gets the complete records that are double. (yeah yeah.. no * should be used in the SELECT) It's just for demonstrating folks!!

SELECT *
FROM table
WHERE tablefield IN (
 SELECT tablefield
 FROM table
 GROUP BY tablefield 
 HAVING (COUNT(tablefield ) > 1)
)

To go even further in the process and DELETE every double record we could do something like make a temporary table, insert the double records, delete it from the original table and insert the saved single records from the temporary table.

5074 viewed | 3 opinion(s)  | del.icio.us | Digg it | Tjarko @ 01/12/05 23:56 cet


Reactions:

dynk wrote.... (site)

Thanks for the SQL help. Also, I like your captcha.

11 July 2007 16:17 cet  

Andy wrote.... (site)

thanks for the solution.

20 December 2007 14:08 cet  

Ben wrote.... (mail)

I used you code but couldn't find the duplicate, but using my code, I get:

select count (*) from table = 121
select count (distinct(tableField)) from table = 120

Why am I not able to return the duplicate record using your code?Please help.

14 February 2008 6:02 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



A dozen apples are how many?? (12 would be a good answer for this)




URL en mail addresses are translated for you... life sometimes is that simple!!
profile-manuscript