【发布时间】:2017-06-13 15:08:29
【问题描述】:
数据库中有一些功能重复。
IE,在一个示例表衣服中,如果列 country、color 和 type 相同,则计为同一行。
我想取出这些重复的。
所以给出示例表:
Clothes
ID COUNTRY COLOR TYPE
11 China Blue PJ
22 Spain Red Pants
39 Spain Grey Pants
51 Spain Grey Pants
70 China Blue PJ
94 Spain Red Pants
我使用以下查询:
SELECT t1.id AS id_1, t2.id AS id_2
FROM clothes t1
LEFT JOIN clothes t2
ON t1.type = t2.type AND t1.country = t2.country AND t1.color = t2.color
WHERE t1.id <> t2.id;
这会导致
id_1 id_2
51 39
39 51
70 11
11 70
22 94
94 22
问题:有什么办法可以避免重复行吗? IE,我想要的是这样的:
id_1 id_2
51 39
70 11
22 94
【问题讨论】:
标签: sql oracle duplicates