Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL -Grab unique column combination from table

Tags:

sql

oracle

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

like image 871
contactmatt Avatar asked Jan 20 '23 07:01

contactmatt


1 Answers

select distinct columnA, columnB from table

or

select columnA, columnB from table
group by columnA, columnB
like image 125
Sachin Shanbhag Avatar answered Jan 31 '23 09:01

Sachin Shanbhag