Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove duplicates by selecting first row from each subgroup in a record set

user13667036Nov 10 2015 — edited Nov 10 2015

Oracle: 11gR2

Windows 7 client

I have a data set (result of a query) which is similar to:

D_rank     product_id      product_desc             category      price     revenue     cost

1               112233          prod1-iphone              phone         200        500          100

1               112233          prod1-iphone4            phone         200        500          100

2               223344          prod2-windows7         OS             300        1000         400

2               223344          prod2-windows7         software     300        1000         400

3               334455          prod3-Mac                 computer   1000       1500        1000

4               445566          prod4-xyz                  misc          2000       800          1200

:                    :               :                                   :               :             :              :

:                    :               :                                   :               :             :              :         

:                    :               :                                   :               :             :              :

As you can notice from first 4 rows, because of the product_desc and category field these ranks are repeated. I need these fields but the first value from each sub-group, so that every rank is unique. I.e.

D_rank     product_id      product_desc             category      price     revenue     cost

1               112233          prod1-iphone              phone         200        500          100

2               223344          prod2-windows7         OS             300        1000         400

3               334455          prod3-Mac                 computer   1000       1500        1000

4               445566          prod4-xyz                  misc          2000       800          1200

:                    :               :                                   :               :             :              :

:                    :               :                                   :               :             :              :         

:                    :               :                                   :               :             :              :

Will appreciate some help.

This post has been answered by Frank Kulash on Nov 10 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2015
Added on Nov 10 2015
4 comments
1,369 views