在Sql Server中查找表中的所有重复项

时间:2015-05-09 16:28:50

标签: sql-server

我有一个包含两列Urls的表,它包含重复项。我循环遍历每一行但不知道检查重复项。我想发送oldurl作为参数来检查重复项并获取它们。我不想要数,但所有重复的列表。任何人都可以帮助我

OldUrl     NewUrl    
---------------------
Google     Google.in
Amazon     Amazon.in

1 个答案:

答案 0 :(得分:0)

SELECT oldurl
FROM mytable
GROUP BY oldurl
HAVING COUNT(*) >1

或者如果您需要查看所有重复的记录:

SELECT mytable.*, t.counter
FROM mytable
INNER JOIN(
SELECT oldurl, COUNT(*) as counter
FROM mytable
GROUP BY oldurl
HAVING COUNT(*) >1) t
ON t.oldurl=mytable.oldurl