Select nth result from a query

Viewed 10276

I'm using SQL Server 2012 and I was wondering if there is a way to select, for example, the third result from a query. I have looked into LIMIT and OFFSET but I'm not 100% sure if it applies to SQL Server, however I've been told that there is something to do what I want in SQL Server 2012.

3 Answers

I would recommend

select * from table ORDER BY OrderingColumn ASC LIMIT n,1

This is a quirk of limit where if you give it a range, it only returns that range. It works in MySQL too.

Can’t you just select the second index? This is the way i would take say the third post in my table.

//index 3 $index3 = DB::query(‘SELECT * from posts’)[2];

Then you will have an array that is ready to go for you.

Related