If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Find Duplicates rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-03, 11:23
Anchala Anchala is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
Find Duplicates rows

Please advise on finding duplicates rows based on 3 columns of a table. I am trying to avoid subqueries..

Example: payment table - policy,amount,coverage are the columns
duplicate row is when all policy, amount, coverage have same data repeated.
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 12:42
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Re: Find Duplicates rows

Quote:
Originally posted by Anchala
Please advise on finding duplicates rows based on 3 columns of a table. I am trying to avoid subqueries..

Example: payment table - policy,amount,coverage are the columns
duplicate row is when all policy, amount, coverage have same data repeated.
Maybe this query might work (but it depends on what you want to do with the result):

select policy, amount, coverage, count(*) from payment
group by policy, amount, coverage
having count(*) > 1
Reply With Quote
  #3 (permalink)  
Old 12-09-03, 15:43
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Re: Find Duplicates rows

Another possibility is the ROWNUMBER() OVER (PARTITION BY policy,amount,coverage ORDER BY ... )

The result from the SELECT is a sequence number column.

Quote:
Originally posted by Anchala
Please advise on finding duplicates rows based on 3 columns of a table. I am trying to avoid subqueries..

Example: payment table - policy,amount,coverage are the columns
duplicate row is when all policy, amount, coverage have same data repeated.
Reply With Quote
  #4 (permalink)  
Old 12-11-03, 04:17
tupiex tupiex is offline
Registered User
 
Join Date: Dec 2003
Location: Johannesburg, South Africa
Posts: 18
DB2 Information

HI

GertK gave you some very useful advise there, thanks Gert.

For other DB2 DBA;s out there, this query he sent will also assit you in determining within an unique index, what are the duplicates. Just remeber to put the columns of the index in the select and group bu clauses.
__________________
Divvy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On