how to get 1001 th record from my table

Posted by Gayathri under Sql Server on 6/7/2013 | Points: 10 | Views : 1051 | Status : [Member] | Replies : 4
I am having around 2 lacs record in my database customer
i want to pick the 1001 th customer and display.


please tell me the query to the same




Responses

Posted by: Gayathri on: 6/7/2013 [Member] Starter | Points: 25

Up
0
Down
Also the query should be faster. kindly give your answers

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rabbil on: 6/7/2013 [Member] Starter | Points: 25

Up
0
Down
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY CustomerId ASC) AS rownumber,
CustomerName
FROM Northwind.dbo.Customers
) AS foo
WHERE rownumber = 1001

Hope this would work...

"I cannot teach anybody anything. I can only make them think"~ Socrates
Thanks And Regards

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gayathri on: 6/7/2013 [Member] Starter | Points: 25

Up
0
Down
thanks for the clue. this would return only the row number.
instead with slight modification here you go
with Records AS(select row_number() over(order by customerid) as 'row', *
from customers)
select * from records
where row=1001

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rabbil on: 6/8/2013 [Member] Starter | Points: 25

Up
0
Down
So,the modified query is reusing the pre-compiled query using "WITH" Clause,which is showing the result in more faster then the earlier query.
Thanks for enlightening me...

"I cannot teach anybody anything. I can only make them think"~ Socrates
Thanks And Regards

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response