473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Query for duplicates

I'm using this to create a view for duplicates , but no of records coming out of this view are more than I'm passing in: can anybody help ?


Expand|Select|Wrap|Line Numbers
  1. CREATE VIEW test AS
  2. (
  3.     SELECT    field1,
  4.     field2,
  5.     field3,field4,
  6.     field5 ,
  7.     field6,
  8.     id,
  9.     field7,
  10.     COUNT(*) AS REC_COUNT
  11.     FROM     tablename    GROUP BY    
  12.             field1,
  13.             field2,
  14.             field3 ,
  15.             field4,
  16.             field5,
  17.             field6,
  18.             id,
  19.             field7
  20.     HAVING    COUNT(*) > 1
Oct 3 '15 #1
3 2650
Hi, Because 'id' is presumably unique and the row has to be exactly the same in every field, and if you group by all those fields and one of them is different it will register as unique and not a duplicate.

If it is just 'id' that is unique in the field, and you remove 'id' totally you'll get the list. If you need 'id', then you have to set up the select query as a sub-query and re-join that to the main table. There are other ways of doing this using rank() and dense rank(). You are able to number your rows by groups, and then you can pick out the rows you want specifically. I would also try to avoid using count(*) if the tables are large. Hope this helps.

Expand|Select|Wrap|Line Numbers
  1. SELECT t1.field1, t1.field2, t1.field3, t1.field4, t1.field5, t1.field6, t1.id, t1.field7
  2.     FROM tablename t1
  3.         INNER JOIN (SELECT field1, field2, field3, field4, field5, field6, field7 , COUNT(*) AS CountOf
  4.                         FROM tablename
  5.                         GROUP BY field1, field2, field3, field4, field5, field6, field7
  6.                         HAVING COUNT(*)>1 ) as t2 ON t1.field1 =  t2.field1 -- if you have to compare all the fields you can add them in here, "and t1.field2 = t2.field2, etc."
  7.  
Oct 3 '15 #2
Hi Vikki,

Thanks a TON....I was playing with that query for a while now and your solution really helped, I was not comparing the whole row excluding the unique id....that's why was getting so many duplicates.....thanks Again!!!
Oct 4 '15 #3
No problem. We've all been there. Glad to help. :)
Oct 5 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tom Mitchell | last post by:
All: I'm stumped on a query. How do I find duplicates in a table where one of the duplicates has values is a certain field and the other doesn't. For example, I have the following table: ...
3
by: Sim Zacks | last post by:
I am using 8.0 beta 1 on an RH 8 Linux server. I have a union query that I am converting from access (where it worked) and it is returning duplicates. The only difference between the two rows is...
16
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
4
by: Scott12345 | last post by:
Hi, here is my situation, I have a DB that tracks machine downtime (30 machines) per day. Several users will update this through the day. I created an append query that creates 30 dummy values and...
0
by: csin | last post by:
I have an Access DB backend for the application I am running, I want to use the built in ability in Access to remove duplicate entries... Say I have table1 with fields field1 field2 and field3,...
1
by: tskmjk55 | last post by:
Recently, I have a requirement to develop a vb.net application wherein the input excel sheet data which has an average of 5000 records should be checked for Internal duplicates (duplicates within the...
11
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time...
5
by: brandon Gadish | last post by:
I am trying to append a table with records from another table. When I run the Append query the first time it works fine, however when I run it a second time it will duplicate the records. I created...
10
by: jacekwbak | last post by:
Hello, I have following problem: table1 id / ArticleCode / ArticleColor 1 / 123 / blue 2 / 123 / blue 3 / 222 / green 4 / 333 / red
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.