0

I am trying to get distinct values with multi column select.

Sample table:

CREATE TABLE DUP_VALUES (ID NUMBER, NAME VARCHAR2(64));

 INSERT INTO DUP_VALUES values (1, 'TEST1');
 INSERT INTO DUP_VALUES values (2, 'TEST1');
 INSERT INTO DUP_VALUES values (3, 'TEST2');
 INSERT INTO DUP_VALUES values (4, 'TEST2');
 INSERT INTO DUP_VALUES values (5, 'TEST1');
 INSERT INTO DUP_VALUES values (6, 'TEST1');
 INSERT INTO DUP_VALUES values (7, 'TEST1');

I want to get

ID NAME
1  TEST1
3  TEST2

I tried with SELECT DISTINCT ID, NAME FROM DUP_VALUES

But, I got all values, because ID is unique.

1 Answer 1

3

Use aggregation:

select min(id) as id, name
from dup_values
group by name;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.