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 )
            Asked
            
        
        
            Active
            
        
            Viewed 1.6k times
        
    12
            
            
        - 
                    See also http://stackoverflow.com/questions/216673/emulate-mysql-limit-clause-in-microsoft-sql-server-2000 – Bill Karwin Dec 04 '09 at 20:27
- 
                    Possible duplicate of [How to implement LIMIT with Microsoft SQL Server?](http://stackoverflow.com/questions/603724/how-to-implement-limit-with-microsoft-sql-server) – e4c5 Dec 17 '16 at 05:18
3 Answers
18
            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
  )
)
 
    
    
        Christian Payne
        
- 7,081
- 5
- 38
- 59
4
            
            
        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
 
    
    
        o.k.w
        
- 25,490
- 6
- 66
- 63
0
            
            
        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)
 
    
    
        jack
        
- 1
 
    