当前位置: 代码迷 >> ASP.NET >> 关键字order附近有语法异常
  详细解决方案

关键字order附近有语法异常

热度:6562   发布时间:2013-02-25 00:00:00.0
关键字order附近有语法错误
select top 10 * from (select top 10 * from (select top 20 * from [User] order by Id asc) order by Id desc) order by Id asc

就这上面这句SQL查询,直接手动在数据库管理器里查询就没问题,但程序运行就会出现:
System.Data.SqlClient.SqlException: 关键字 'order' 附近有语法错误。

在线请求帮助,多谢

------解决方案--------------------------------------------------------
select top 10 * from (select top 10 * from (select top 20 * from [User] order by Id asc) tt order by [Id] desc) order by [Id] asc
------解决方案--------------------------------------------------------
select top 10 * from (select top 10 * from (select top 20 * from [User] t1 order by t1.Id asc) t2 order by t2.Id desc) t3 order by t3.Id asc

这条语句涉及到user表及两个select计算出来的表,均包含ID列,需要加前缀区分
  相关解决方案