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

前端 未结 7 900
耶瑟儿~
耶瑟儿~ 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:38

    You can also use rowcount, but TOP is probably better and cleaner, hence the upvote for Mehrdad

    SET ROWCOUNT 10
    SELECT * FROM dbo.Orders
    WHERE EmployeeID = 5
    ORDER BY OrderDate
    
    SET ROWCOUNT 0
    

提交回复
热议问题