10 个解决方案
#1
根据你想排序的字段,Top 1 ... Order By Col Desc
#2
select top1 * from 表order by 主键
#3
select top1 * from 表order by 主键 desc
忘了加倒序
#4
表对于不同的排序 最后一行记录都不一样啊。
#5
count(id)
#6
不指定表名的话,你应该使用动态 SQL 了,
-- 注意 from 后面和 order by 前面,要加空格
declare @sql varchar(800)
declare @tname varchar(100)
set @tname = 'sysobjects '
set @sql = 'select top1 * from ' + @tname + ' order by 主键 desc'
exec @sql
#7
前面说到的(使用主键)
select * from tablename order by 主键 desc
如果没有设置主键(使用自增列)
select *,identity(int,1,1) as id into #t from tablename
select * from #t order by id desc
select * from tablename order by 主键 desc
如果没有设置主键(使用自增列)
select *,identity(int,1,1) as id into #t from tablename
select * from #t order by id desc
#8
select * from table where ROWNUM<2 ORDER BY table_id DESC;
#9
用游标 feth last from。。。
#10
sys.objects 替换成各张表就行:
select * from(
select ROW_NUMBER()over(order by (select 0)) as id,* from sys.objects
) t where id = (select COUNT(*) from sys.objects)
#1
根据你想排序的字段,Top 1 ... Order By Col Desc
#2
select top1 * from 表order by 主键
#3
select top1 * from 表order by 主键 desc
忘了加倒序
#4
表对于不同的排序 最后一行记录都不一样啊。
#5
count(id)
#6
不指定表名的话,你应该使用动态 SQL 了,
-- 注意 from 后面和 order by 前面,要加空格
declare @sql varchar(800)
declare @tname varchar(100)
set @tname = 'sysobjects '
set @sql = 'select top1 * from ' + @tname + ' order by 主键 desc'
exec @sql
#7
前面说到的(使用主键)
select * from tablename order by 主键 desc
如果没有设置主键(使用自增列)
select *,identity(int,1,1) as id into #t from tablename
select * from #t order by id desc
select * from tablename order by 主键 desc
如果没有设置主键(使用自增列)
select *,identity(int,1,1) as id into #t from tablename
select * from #t order by id desc
#8
select * from table where ROWNUM<2 ORDER BY table_id DESC;
#9
用游标 feth last from。。。
#10
sys.objects 替换成各张表就行:
select * from(
select ROW_NUMBER()over(order by (select 0)) as id,* from sys.objects
) t where id = (select COUNT(*) from sys.objects)