获取两个字段值的唯一组合 [英] Fetch unique combinations of two field values
本文介绍了获取两个字段值的唯一组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能以前有人问过,但我找不到答案.
Probably it has been asked before but I cannot find an answer.
表数据有两列:
Source Dest
1 2
1 2
2 1
3 1
我试图提出一个MS Access 2003 SQL查询,该查询将返回:
I trying to come up with a MS Access 2003 SQL query that will return:
1 2
3 1
但都无济于事.请帮忙!
But all to no avail. Please help!
更新:确切地说,我正在尝试排除2,1,因为已经包含1,2.我只需要顺序无关紧要的唯一组合.
UPDATE: exactly, I'm trying to exclude 2,1 because 1,2 already included. I need only unique combinations where sequence doesn't matter.
推荐答案
对于Ms Access,您可以尝试
For Ms Access you can try
SELECT DISTINCT
*
FROM Table1 tM
WHERE NOT EXISTS(SELECT 1 FROM Table1 t WHERE tM.Source = t.Dest AND tM.Dest = t.Source AND tm.Source > t.Source)
表数据示例,这是相同的...
Example with table Data, which is the same...
SELECT DISTINCT
*
FROM Data tM
WHERE NOT EXISTS(SELECT 1 FROM Data t WHERE tM.Source = t.Dest AND tM.Dest = t.Source AND tm.Source > t.Source)
或(格式和访问权限格式好)
SELECT DISTINCT *
FROM Data AS tM
WHERE (((Exists (SELECT 1 FROM Data t WHERE tM.Source = t.Dest AND tM.Dest = t.Source AND tm.Source > t.Source))=False));
这篇关于获取两个字段值的唯一组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文