473,397 Members | 2,084 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,397 software developers and data experts.

find and print out the duplicate record

cbs
hi all,

do you know how to print out the duplicate rec ?

i m using the syntax

select id,IssueDate,ReportName,RevNo,Factory,
count(*) from mytable group by
IssueDate,ReportName,RevNo,Factory
having count(*) > 1;

* if i added the field "id" and group by, nothing print out.
because " id" is uquine. PK

now i can print out only 1 record which has duplicate in 4 times.

but in need to pirnt out all duplicate rec to the screen idendifed by the
id,
any idea ?

thanks
regards,
Bily

~
~
~
Jul 23 '05 #1
2 1612
cbs wrote:
do you know how to print out the duplicate rec ?

i m using the syntax

select id,IssueDate,ReportName,RevNo,Factory,
count(*) from mytable group by
IssueDate,ReportName,RevNo,Factory
having count(*) > 1;

now i can print out only 1 record which has
duplicate in 4 times.
but in need to pirnt out all duplicate rec to
the screen idendifed by the id, any idea ?


I believe the following should do the trick:

SELECT
t1.*
FROM
mytable AS t1, mytable AS t2
WHERE
t1.IssueDate = t2.IssueDate
AND
t1.ReportName = t2.ReportName
AND
t1.RevNo = t2.RevNo
AND
t1.Factory = t2.Factory
AND
t1.id != t2.id
GROUP BY
id;

A small test case:

SELECT * FROM mytable;

id | IssueDate | ReportName | RevNo | Factory
1 | 2005-05-05 | dailystats | 5 | suse
2 | 2005-05-05 | dailystats | 5 | suse
3 | 2005-05-05 | dailystats | 5 | suse
6 | 2005-05-05 | dailystats | 5 | suse
4 | 2005-05-08 | security | 4 | caldera
5 | 2005-05-07 | learning | 3 | redhat
7 | 2005-05-07 | shells | 14 | solaris
8 | 2005-05-07 | learning | 3 | redhat
9 | 2005-05-05 | dailystats | 5 | microsoft

SELECT
t1.*
FROM
mytable AS t1, mytable AS t2
WHERE
t1.IssueDate = t2.IssueDate
AND
t1.ReportName = t2.ReportName
AND
t1.RevNo = t2.RevNo
AND
t1.Factory = t2.Factory
AND
t1.id!=t2.id
GROUP BY
id;

id | IssueDate | ReportName | RevNo | Factory
1 | 2005-05-05 | dailystats | 5 | suse
2 | 2005-05-05 | dailystats | 5 | suse
3 | 2005-05-05 | dailystats | 5 | suse
5 | 2005-05-07 | learning | 3 | redhat
6 | 2005-05-05 | dailystats | 5 | suse
8 | 2005-05-07 | learning | 3 | redhat

--
Bart

Jul 23 '05 #2


Bart Van der Donck schrieb:
cbs wrote:
do you know how to print out the duplicate rec ?


Hi Bart,

have a look at a recent posting in this newsgroup regarding the same
question.
Its title was: "Best way for finding duplicate entries in table?" and
it started on June 1st with Bill Karwin, myself and Aggro as posters.
Bill showed the best ways to print them out or to delete the
duplicates, at least, if you have a MySQL version that allows
Sub-SELECTs.

HTH,

Andy

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Giloosh | last post by:
Hello, i need some help if possible... i have a payments table with over 500 records i want to run a query that searches through the table spotting out any duplicate ID#'s and Dates. So basically...
1
by: Robert | last post by:
How can I query an existing table and update a field in each record in the table with the occurrence count of each record e.g. update field to 1 (= first record occurrence), update field to 2 for...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
3
by: Nhmiller | last post by:
I searched here for an answer. I am entering records into a database, and it would save a lot of time if I could duplicate a record that is very similar to the new one I am about to enter, then...
3
by: Sarah Smith via AccessMonster.com | last post by:
I am creating a database of documents that need to be worked on, are int eh proress of being worked on, and have been completed. Sometimes the same document (an updated version) comes back for more...
0
by: Cyberwolf | last post by:
OK, how to explain this. I have a table that will feed into another table using an append query. What I want to do is look at the table I am appending the record to to check for a duplicate...
1
by: aknoch | last post by:
My basic situation is this - I ONLY want duplicates, so the opposite of DISTINCT: I have two tables. Ordinarily, Table1ColumnA corresponds in a one to one ratio with Table2ColumnB through a...
2
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : ...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.