Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsulaiman abouabdah
5,314 PointsMS SQL OFFSET
MS SQL and Oracle
To page through results you can either use the OFFSET keyword in conjunction with the FETCH keyword. Cannot be used with TOP.
SELECT <columns> FROM <table> OFFSET <skipped rows> ROWS FETCH NEXT <# of rows> ROWS ONLY;
I have tried this and it didn't work on MS SQL server 2014
Can you please show us a demo of how to make it work?
1 Answer
Steven Parker
231,236 PointsFETCH
is a T-SQL operator for use with a cursor. Are you sure that's what you need? If so, please show the complete T-SQL where you establish the cursor.
If you just want a limited number of rows from an ordinary query you should use TOP
instead.
sulaiman abouabdah
5,314 Pointssulaiman abouabdah
5,314 PointsI have no idea what T-SQL means. I am still new at this.
I am trying to do as we were taught in the video that you can use OFFSET in order to start in a certain row and then start printing the next limited rows. How can I do that in MS SQL Server?
Steven Parker
231,236 PointsSteven Parker
231,236 PointsNote that using both
TOP
andOFFSET
requires a sub-query, andOFFSET
requiresORDER BY
: