7/27/11

SQL code for fetching first 10 records starting with 50

In many interviews i had been asked questions like this:
Write a code for fetching first 10 records starting with 50.
Now i decided to post it here for me and everyone else who may need it:
(You may run this query in AdventureWorks sample Database )

WITH Persons AS
(
    SELECT FirstName,LastName,
    ROW_NUMBER() OVER (ORDER BY LastName) AS 'RowNumber'
    FROM Person.Contact
)
SELECT FirstName,LastName
FROM Persons
WHERE RowNumber BETWEEN 50 AND 60;

No comments:

Post a Comment

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...