Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Counting duplicates in SQL

Re: Counting duplicates in SQL

From: DA Morgan <damorgan_at_psoug.org>
Date: Sat, 02 Sep 2006 09:47:54 -0700
Message-ID: <1157215673.608206@bubbleator.drizzle.com>


Thomas Kellerer wrote:

> Jack wrote on 02.09.2006 17:32:

>> SELECT Product_ID, Product_Name,
>> (SELECT MIN(Product_ID) FROM Products AS P1
>> WHERE Products.Product_Name = P1.Product_Name) AS OldID
>> FROM Products WHERE Product_ID NOT IN
>> (SELECT MIN(Product_ID) FROM Products AS P2
>> WHERE Products.Product_Name = P2.Product_Name)
>>
>> 85157 Chips 84050
>> 82103 Fish 76929
>> 82103 Fish 76929
>> 99999 Sausage 82785
>> 83780 Sausage 82785
>>
>>
>> So for example for "Sausage" I would like to report how many rows have
>> an ID
>> of 82785, 83780 and 99999 respectively. I can't see how I can adapt my
>> statement above. Is there another approach using just SQL?
> 
> SELECT product_id, count(*)
> FROM
> (
>   your statement goes here
> )
> WHERE product_name = 'Sausage'
> GROUP BY product_id
> 
> Thomas

to which I would add HAVING COUNT(*) > 1

-- 
Puget Sound Oracle Users Group
Received on Sat Sep 02 2006 - 11:47:54 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US