[英]SQL: use distinct values in one column to select all corresponding distinct values in another column
Suppose I have a data set such as this: 假设我有一个像这样的数据集:
ColA ColB
==== ====
Foo Green
Foo Purple
Bar Magenta
Bar Green
Foo Purple
Bar Purple
Bar Purple
Foo Green
Bar Green
I would like to query this data and return the below. 我想查询此数据并返回以下内容。 Essentially, take all distinct values from ColA (Foo & Bar) and return all distinct values for EACH of them from ColB:
本质上,从ColA(Foo和Bar)中获取所有不同的值,并从ColB中返回每个EACH的所有不同值:
ColA ColB
==== ====
Foo Green
Foo Purple
Bar Magenta
Bar Green
Bar Purple
I know I'm overthinking this...but I can't seem to hammer it out... 我知道我想得太多了...但是我似乎无法解决...
Please use of of the below - 请使用以下-
SELECT DISTINCT cola,colb FROM yourtableName
OR 要么
SELECT cola,colb From yourtableName
GROUP BY cola,colb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.