What is the Equivalent syntax of mysql “ LIMIT ” clause in SQL Server

本小妞迷上赌 提交于 2019-12-20 19:42:20

问题


What is the Equivalent syntax of MySQL " LIMIT " clause in SQL Server . I would like to use it for doing paging of my results. (want to show records5 to 10 )


回答1:


The closest thing is TOP:

Select top 5 * from tablename

You can get a range ( rows 5 - 10)

SELECT * FROM (
  SELECT TOP n * FROM (
    SELECT TOP z columns      -- (z=n+skip)
    FROM tablename
    ORDER BY key ASC
  )
)



回答2:


The closest to it is SELECT TOP X but it is only equivalent to LIMIT X.

For LIMIT X, Y, there is no direct MS-SQL equivalent (as far as I know). Christian's solution is a good one though.

MSSQL2005 (onwards) has the ROW_NUMBER syntax which might be useful:
http://msdn.microsoft.com/en-us/library/ms186734%28SQL.90%29.aspx




回答3:


cont=until desired number is starting to get results limit=Want to see how many variables

SELECT TOP (limit) cve_persona FROM persona WHERE (cve_persona > cont)



来源:https://stackoverflow.com/questions/1736563/what-is-the-equivalent-syntax-of-mysql-limit-clause-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!