<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[SQLServer数据库多种方式查找重复记录]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[SQLSERVER]]></category>
<pubDate>Thu, 22 May 2008 08:39:45 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	SQL Server数据库多种方式查找重复记录:<br/>示例：表stuinfo，有三个字段recno(自增)，stuid，stuname<br/>建该表的Sql语句如下：<br/><textarea name="code" class="sql" rows="15" cols="100">
CREATE TABLE [StuInfo] (
[recno] [int] IDENTITY (1， 1) NOT NULL ，
[stuid] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ，
[stuname] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
</textarea><br/>1.查某一列(或多列)的重复值(只可以查出重复记录的值，不能查出整个记录的信息)<br/>例如:查找stuid，stuname重复的记录<br/><textarea name="code" class="sql" rows="15" cols="100">
select stuid，stuname from stuinfo
group by stuid，stuname
having(count(*))>1
</textarea><br/>2.查某一列有重复值的记录(此方法查出的是所有重复的记录，如果有两条记录重复的，就查出两条)<br/>例如:查找stuid重复的记录<br/><textarea name="code" class="sql" rows="15" cols="100">
select * from stuinfo
where stuid in (
select stuid from stuinfo
group by stuid
having(count(*))>1
)
</textarea><br/>3.查某一列有重复值的记录(只显示多余的记录，也就是说如果有三条记录重复的，就显示两条)<br/>前提：需有一个不重复的列，此示例为recno。<br/>例如:查找stuid重复的记录<br/><textarea name="code" class="sql" rows="15" cols="100">
select * from stuinfo s1
where recno not in (
select max(recno) from stuinfo s2
where s1.stuid=s2.stuid
</textarea><br/>Tags - <a href="https://blog.liuts.com/tags/%25E9%2587%258D%25E5%25A4%258D%25E8%25AE%25B0%25E5%25BD%2595/" rel="tag">重复记录</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] SQLServer数据库多种方式查找重复记录]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>