how to select first N rows from a table in T-SQL?

前端 未结 7 902
耶瑟儿~
耶瑟儿~ 2020-12-10 10:54

Is there any way to select, for example, first 10 rows of a table in T-SQL (working MSSQL)?
I think I saw something in Oracle defined as rownum meta variable, used in a

7条回答
  •  我在风中等你
    2020-12-10 11:32

    select top(@count) * from users
    

    If @count is a constant, you can drop the parentheses:

    select top 42 * from users
    

    (the latter works on SQL Server 2000 too, while the former requires at least 2005)

提交回复
热议问题