select top 1 * from (select top 2 * from 表) order by id DESC
:) select top 1 * from (select top 2 * from tb_dd) a order by id DESC
Please try it:(已测试通过)select kk.* from (select top 1 * from table)gg , (select top 2 * from table) kk where gg.id!=kk.id
--测试数据 create table ta(id int, name varchar(10)) insert ta select 1, '张锦' union all select 2, '张锦' union all select 3, '张锦' union all select 4, '李强' --查询 select top 1 * from (select top 2 * from ta where name='张锦')a order by id desc /* select top 1 * from ta where id not in( select top 1 id from ta where name='张锦') */ --清除 drop table ta
select top 1 * from table where id not in ( select top 1 id from table )
select top 1 * from table1 where id <5 and id not in (select top 1 id from table1)
还要带条件的。比如查询姓名="在" 和推荐与审核为真的第二条记录 怎样用一条sql语句查询出表里的第二条记录。 select top 2 * into #aa where 姓名='在' and 推荐='t' and 审核='t' order by id descselect top 1 * from #aa
或才select top 2 * into #aa where 姓名='在' and 推荐='t' and 审核='t' order by id descselect * from (select top 1 * from #aa ) t ,(select top 2 * from #aa) g whre g.id<>t.id
SELECT TOP 2 * FROM T_WenZhang ORDER BY WZ_Time DESC
错了,还是应该是 select top 1 * from T_WenZhang where WZ_Class='社区通告' and (Wz_id NOT IN (SELECT TOP 1 Wz_id FROM T_WenZhang where WZ_Class='社区通告' ORDER BY WZ_time))
select top 1 * from 表 where id not in (select top 1 id from 表 order by id asc)
select top 1 * from 表 where [id] not in(select top 1 [id] from 表)
select top 2 from tablename where field not in (select top 1 id from 表 order by id asc)
select top 2 from tablename where field not in (select top 1 id from tablename order by id asc)
select top 1 * from (select top 2 * from tb_dd) a order by id DESC
from (select top 1 * from table)gg , (select top 2 * from table) kk
where gg.id!=kk.id
create table ta(id int, name varchar(10))
insert ta select 1, '张锦' union all select 2, '张锦'
union all select 3, '张锦' union all select 4, '李强'
--查询
select top 1 *
from (select top 2 *
from ta
where name='张锦')a
order by id desc
/*
select top 1 *
from ta
where id not in(
select top 1 id
from ta
where name='张锦')
*/
--清除
drop table ta
(select top 1 id from table1)
怎样用一条sql语句查询出表里的第二条记录。
select top 2 * into #aa where 姓名='在' and 推荐='t' and 审核='t' order by id descselect top 1 * from #aa
whre g.id<>t.id
FROM T_WenZhang
ORDER BY WZ_Time DESC
select top 1 * from T_WenZhang where WZ_Class='社区通告' and (Wz_id NOT IN (SELECT TOP 1 Wz_id FROM T_WenZhang where WZ_Class='社区通告' ORDER BY WZ_time))
where id not in (select top 1 id from 表 order by id asc)
where field not in (select top 1 id from 表 order by id asc)
where field not in (select top 1 id from tablename order by id asc)