Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2008

    Unanswered: Limiting rows returned by result sets

    In MySQL we use "SELECT (....) LIMIT 0, 10" to only return the first 0 to 10 records. Alternatively we could do "LIMIT 10, 20" to return the 10th to 20th records.

    What's the equivilent of this in SQL Server?


  2. #2
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    there is no such thing as "the first 0 to 10 records". You want to use SELECT TOP or SET ROWCOUNT.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
    neither SELECT TOP nor SET ROWCOUNT can easily do rows 11 through 20

    FYI dbguyfh, LIMIT 10,20 is actually rows 11 through 30 | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2003
    Provided Answers: 17
    In SQL 2005, this can be done with CTEs and the ROW_NUMBER function. I believe the examples are in Books Online. If not there, then tere will probably be a number of examples on various blogs. Just google for Common Table Expressions.

  5. #5
    Join Date
    Sep 2005
    You can google lots of examples for doing this in SQL Server. Most of them use sub queries with a TOP clause (descending order) within another query with a TOP clause.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts