SQL -Grab unique combination of columns from a table

In Oracle, I have a table called "MyTable". There are columns “A” and “B” in this table. I want to find every unique combination of "A" and "B". How should I do it? I would prefer to do this in SQL rather than in PL / SQL.

Example:

Column A | Column B

Dog           Cat
Cat           Dog
Horse         Cat
Dog           Cat

The unique combination above should return 3 rows.

thank

+3
source share
2 answers
select distinct columnA, columnB from table

or

select columnA, columnB from table
group by columnA, columnB
+7
source

Do it like this:

Select A, B
From MyTable
Group by A, B
0
source

Source: https://habr.com/ru/post/1796313/


All Articles