contactmatt
contactmatt

Reputation: 18610

SQL -Grab unique column combination from table

In Oracle, I have a table called "MyTable". This table has columns 'A' and 'B'. I want to find every unique combination of 'A' and 'B'. How would I do this? I'd prefer to do this in SQL rather than PL/SQL.

Example:

Column A | Column B

Dog           Cat
Cat           Dog
Horse         Cat
Dog           Cat

A unique combination above should return 3 rows.

Thank You

Upvotes: 4

Views: 12451

Answers (2)

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

select distinct columnA, columnB from table

or

select columnA, columnB from table
group by columnA, columnB

Upvotes: 9

Cosmin
Cosmin

Reputation: 2385

Do it like this:

Select A, B
From MyTable
Group by A, B

Upvotes: 0

Related Questions