首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一 SQL语句解决方案

2012-02-24 
求一 SQL语句表test,字段id1是唯一的,数据如下:idid1112223243536用一条语句取出id不重复的记录,应该怎么

求一 SQL语句
表test,字段id1是唯一的,数据如下:
id         id1
1             1
2             2
2             3
2             4
3             5
3             6

用一条语句取出id不重复的记录,应该怎么写?

[解决办法]
select * from test a
where not exists(select * from test where id=a.id and id1 <> a.id1)
[解决办法]
select id,max(id1) from test group by id
[解决办法]
select id,max(id1) from test group by id having count(*)=1
[解决办法]
id id1

表名:ta
select * from ta as a
where (select count(*) from ta where id=a.id)!> 1

热点排行