MYSQL在两列中选择DISTINCT值

我想在数据库中选择不同的值。让我来看一个简单的例子。

表:

foo bar

--- ---

a c

c f

d a

c a

f c

a c

d a

a c

c a

f c

是的,假设我的SQL是SELECT DISTINCT foo, bar from table。这些是我的结果:

foo bar

--- ---

a c

c f

d a

c a

f c

但是,问题在于a c/ 重复的c a顺序不同。我不想选择这些,我希望这两列中都有不同的值,请帮忙!

回答:

非常邪恶和邪恶:

select distinct

least(foo, bar) as value1

, greatest(foo, bar) as value2

from table

以上是 MYSQL在两列中选择DISTINCT值 的全部内容, 来源链接: utcz.com/qa/421621.html

回到顶部