View previous topic :: View next topic
|
Author |
Message |
mvkumar22 Warnings : 1 New User
Joined: 26 Dec 2007 Posts: 8 Location: Chennai
|
|
|
|
Hi,
I have a table which contains 3 columns which can allow duplicates. Now i want to write a query so that i want to retreive ONLY DUPLICATES for all the columns.
Thnaks in Advance,
Vijay |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
How many rows are in the table?
What if there are more than 2 rows that have all 3 columns duplicated? Do you want to retrieve ALL of the duplicates or only those rows that are not the "first" row for a particular set of values (i.e. if 2 rows match, do you want both selected or only 1 - if 3 rows match, do you want all 3 or only 2)? |
|
Back to top |
|
|
bbessa
New User
Joined: 03 Aug 2006 Posts: 13 Location: Brazil
|
|
|
|
Hi.
Assuming you just want to show distinct rows that are duplicated and a row count for how many duplicates exist:
Code: |
SELECT COL1, COL2, COL3, ROWCOUNT FROM
(
SELECT DISTINCT COL1,COL2,COL3,COUNT(*) AS ROWCOUNT
FROM OWNER.TABLE
GROUP BY COL1,COL2,COL3
) AS T
WHERE ROWCOUNT > 1
|
I don't really know if it's the best solution but it does the job.
If the results provided by this query are not what you wanted then you might want to look into mr. scherrer's questions in the previous post and supply more details on your demand.
My regards,
Bernardo |
|
Back to top |
|
|
|