SQL SELECT DISTINCT-如何在不考虑列顺序的情况下选择不同的对? [英] Sql SELECT DISTINCT - How can I select distinct couple without considering columns' order?

查看:140
本文介绍了SQL SELECT DISTINCT-如何在不考虑列顺序的情况下选择不同的对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张这样的桌子

ID | Sender | Receiver
 0 | EmailA | EmailB
 1 | EmailB | EmailA
 2 | EmailA | EmailB
 3 | EmailA | EmailC
 4 | EmailC | EmailA 
...

,我只选择A所在的对.我的意思是,我要这些行:

and I want to select only the couples in which A is. I mean, I want the rows:

 0 | EmailA | EmailB
 1 | EmailA | EmailC 

我不在乎我会得到

 0 | EmailA | EmailB 

 1 | EmailB | EmailA

因为在我的情况下,A,B与B,A相同,但是我只需要一次.

because in my case A,B is the same as B,A but I need it only once.

我看到了许多类似问题的答案,但我无法解决问题.非常感谢.

I saw many answers to questions like this but I can't solve my problem. Thank you very much.

推荐答案

从收件箱中选择*,其中(发件人='myself'和接收者='target')或(发件人='target'和接收者='myself')顺序自

select * from inbox where (sender = 'myself' and receiver='target') or (sender = 'target' and receiver='myself') order by since

这篇关于SQL SELECT DISTINCT-如何在不考虑列顺序的情况下选择不同的对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆