不工作在我下面的查询:限制SQL
Select * from DimCustomer
order by MiddleName desc LIMIT 5
获得以下错误:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'LIMIT'.
不工作在我下面的查询:限制SQL
Select * from DimCustomer
order by MiddleName desc LIMIT 5
获得以下错误:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'LIMIT'.
SQL Server不使用limit
这样的,它使用top
代替。
select top 5 * from DimCustomer order by MiddleName desc
如果您正在寻找分页,您可以在SQL Server中使用offset
和fetch
2012+
select *
from DimCustomer
order by MiddleName desc
offset 0 rows
fetch next 5 rows only;
更多的模式和分页选项,点击这里:Pagination with offset/fetch
: A better way - Aaron Betrand
但为什么LIMIT在这种情况下不起作用? – user3652369
@ user3652369因为你在SQL服务器上? – SqlZim
是的,我在使用MSSQL 2012的SQL服务器上,数据库是AdventureWorksDW2012 – user3652369
像人类语言,SQL有方言。确保始终检查您正在使用的特定数据库引擎的文档。 –