排除字段重复行的SQL
--
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[test]
GO
CREATE TABLE [dbo].[test] (
?[id] [int] IDENTITY (1, 1) NOT NULL ,
?[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
?[score] [int] NULL
) ON [PRIMARY]
GO
truncate table test
Insert into test(name,score)
select 'a',11 union
select 'b',22 union
select 'b',33 union
select 'c',44 union
select 'c',55
--
SELECT * FROM test
select * from test where [id] in (select [id] from
?(
??select name,id=(select min([id]) from test where [name]=test1.name) from
??(select distinct [name] from test)test1
?)test2
)
或者
select * from test where [id] in(select min([id]) from test group by name)
?
轉(zhuǎn)載于:https://www.cnblogs.com/guodaxia/archive/2007/11/30/978027.html
總結(jié)
以上是生活随笔為你收集整理的排除字段重复行的SQL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SharePoint优秀blog文章汇总
- 下一篇: Microsoft .NET Compa