oracle SQL - 从表中获取唯一的列组合

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5195262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:56:07  来源:igfitidea点击:

SQL -Grab unique column combination from table

sqloracle

提问by contactmatt

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.

在 Oracle 中,我有一个名为“MyTable”的表。该表具有“A”和“B”列。我想找到“A”和“B”的每一个独特组合。我该怎么做?我更喜欢在 SQL 而不是 PL/SQL 中执行此操作。

Example:

例子:

Column A | Column B

A列| B栏

Dog           Cat
Cat           Dog
Horse         Cat
Dog           Cat

A unique combination above should return 3 rows.

上面的唯一组合应返回 3 行。

Thank You

谢谢你

回答by Sachin Shanbhag

select distinct columnA, columnB from table

or

或者

select columnA, columnB from table
group by columnA, columnB

回答by Cosmin

Do it like this:

像这样做:

Select A, B
From MyTable
Group by A, B