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 > Select Duplicate Values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-09, 16:41
37Seconds 37Seconds is offline
Registered User
 
Join Date: Sep 2009
Posts: 1
Select Duplicate Values

I am trying to select duplicate values for a field in a table. The table looks like the following:

Code:
OID   Product    Serial    Status
1     100          abcd        3
2     100          abcf        4
3     100          abcd        3
4     101          ebcd        3
5     101          ebcf        4
6     101          ebcd        3
I would like my result set to be like the following:

Code:
Product    Serial    Status    Count
100          abcd       3       2
101          abcd       3       2
Any ideas on how to get these results?
Reply With Quote
  #2 (permalink)  
Old 09-23-09, 16:55
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I'm sure the query would include the GROUP BY and HAVING clauses. You can find samples in the manual or in the wonderful SQL Cookbook by Graeme Birchall, which is available for free download.
Reply With Quote
  #3 (permalink)  
Old 09-23-09, 18:04
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by 37Seconds
I am trying to select duplicate values for a field in a table. The table looks like the following:

Code:
OID   Product    Serial    Status
1     100          abcd        3
2     100          abcf        4
3     100          abcd        3
4     101          ebcd        3
5     101          ebcf        4
6     101          ebcd        3
I would like my result set to be like the following:

Code:
Product    Serial    Status    Count
100          abcd       3       2
101          abcd       3       2
Any ideas on how to get these results?
Code:
Select Product, Serial, Status, count(*) count
from table1
group by Product, Serial, Status
having count(*) > 1
Lenny
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