Distinct values for a portion of a column list

Need to develop a script that selects values when the first two selected columns are distinct, but the remaining columns are not distinct.

Need all values when only the first two requested columns are distinct and the remaining column values are not distinct

create table tab2(serial_number number,stock_number number, weight number, class number);
insert into tab2 values(100,4,5,9);
insert into tab2 values(100,5,5,8);
insert into tab2 values(100,5,5,9);
insert into tab2 values(100,9,6,7);
insert into tab2 values(101,4,5,9);
insert into tab2 values(102,5,6,8);
insert into tab2 values(102,6,5,9);
insert into tab2 values(103,4,5,9);
insert into tab2 values(110,1,6,19);
insert into tab2 values(110,1,5,9);
insert into tab2 values(110,2,5,9);
commit;


select distinct serial_number, stock_number, weight, class
from tab2

returns values only when all four columns contain a distinct combination of values:

SERIAL_NUMBER STOCK_NUMBER     WEIGHT      CLASS
------------- ------------ ---------- ----------
          100                               9                        6                    7
          100                               5                        5                   8
          103                              4                          5                  9
          110                              1                         5                  9
          100                              4                         5                  9
          100                              5                        5                   9
          110                              2                        5                   9
          101                              4                        5                   9
          102                              5                        6                   8
          102                              6                        5                   9
         
desired results:
SERIAL_NUMBER STOCK_NUMBER     WEIGHT      CLASS
------------- ------------ ---------- ----------
        100                             5                          5                  8
        100                             5                          5                  9
        110                             1                          6                19
        110                             1                          5                  9
J RAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

johnsoneSenior Oracle DBACommented:
This gives me the results you asked for:
SELECT serial_number, 
       stock_number, 
       weight, 
       class 
FROM   tab2 
WHERE  ( serial_number, stock_number ) IN (SELECT serial_number, 
                                                  stock_number 
                                           FROM   tab2 
                                           GROUP  BY serial_number, 
                                                     stock_number 
                                           HAVING Count(1) > 1); 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J RAuthor Commented:
Yes it does.  Thank you  very much..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.