Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Its All About SQL Server
Browse by Tags · View All
Sql Server 2008 39
SQL Server 2012 39
Sql Server 2005 37
SQL Server Basics 11
TSQL Tips n Tricks 11
Performance Tuning 11
Sql Server Management 10
SQL Server Log 9
SQL Server Errors 9
Scripts 8

Archive · View All
July 2012 12
August 2012 8
September 2012 6
June 2012 6
November 2011 5
October 2011 3
August 2011 3
November 2012 2
October 2012 2
January 2012 2

SQL Server: Limit (MySQL) equal Function in SQL Server

Jul 11 2012 10:23AM by aasim abdullah   

In MySQL, Limit is a powerful function used with SELECT query to return rows BUT within given range. We commonly need it when returning only required rows to application according to paging range. For example to return rows from 11 to 15 we will use following query in MySQL
SELECT * FROM MyTable LIMIT 11, 5

In SQL Server, same functionality can be achieved with three different ways.
1.       With Derived Table (Most inefficient way, but applicable to all versions of SQL Server)

SELECT  *
      FROM    ( SELECT    *, ROW_NUMBER() OVER ( ORDER BY ColumnName ) AS RowNum
          FROM      MyTable ) DerivedTable
       WHERE   RowNum >= 11
        ANDRowNum <= 11 + ( 5 - 1 )

2.       With CTE Common Table Expression (Applicable to SQL Server 2005/2008/2012)
   ;
     WITH   CTE
          AS ( SELECT   *, ROW_NUMBER() OVER ( ORDER BY ColumnName ) AS RowNum
               FROM     MyTable)
    SELECT  *
    FROM    CTE
    WHERE   RowNum >= 11
            ANDRowNum <= 11 + ( 5 - 1 )

3.       With OFFSET_ROW FETCH (Applicable to SQL Server 2012 Only)
        Here “OFFSET means, how many rows to skip, “ROWS FETCH NEXT” means, how many rows to skip

 SELECT * FROM MyTable  
        OFFSET 10
        ROWS FETCH NEXT 5 ROWS ONLY;



Republished from Connect SQL [12 clicks].  Read the original version here [2 clicks].

aasim abdullah
23 · 7% · 2372
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SQL Server: Limit (MySQL) equal Function in SQL Server" rated 5 out of 5 by 1 readers
SQL Server: Limit (MySQL) equal Function in SQL Server , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]