SQL Server Performance

Sintax LIMIT, but in SQL server

Discussion in 'Getting Started' started by carrascojg, Jul 8, 2008.

  1. carrascojg New Member

    Dear friends,
    Mysql engine support LIMIT in SQL sintax, this way i can return a range of rows.
    How can i do this with SQL server ?
    Thank's [^o)]
  2. FrankKalis Moderator

    If you are on SQL erver 2005 you can use the ROW_NUMBER() function for this.
  3. FrankKalis Moderator

    Wait... My Mistake. Have a look at TOP()
  4. Madhivanan Moderator

    Also dont forget to use ORDER BY clause whe you use TOP [:)]
  5. carrascojg New Member

    Dear Friends, LIMIT in Mysql doesn't work like TOP, because TOP only gime rows from the start or table.
    LIMIT have two parameters and it work like a range. For example SELECT .... LIMIT 3,6 This way i have a range of rows between 3 and 6 row.
    This kind of solution is what i need to build.
    Thank's
  6. Madhivanan Moderator

    [quote user="carrascojg"]
    Dear Friends, LIMIT in Mysql doesn't work like TOP, because TOP only gime rows from the start or table.
    LIMIT have two parameters and it work like a range. For example SELECT .... LIMIT 3,6 This way i have a range of rows between 3 and 6 row.
    This kind of solution is what i need to build.
    Thank's
    [/quote]
    Search for Pagination
  7. FrankKalis Moderator

    [quote user="carrascojg"]
    Dear Friends, LIMIT in Mysql doesn't work like TOP, because TOP only gime rows from the start or table.
    LIMIT have two parameters and it work like a range. For example SELECT .... LIMIT 3,6 This way i have a range of rows between 3 and 6 row.
    This kind of solution is what i need to build.
    [/quote]
    No, TOP doesn't give rows from the start of a table. At least that is not guaranteed all the time. That's why you need an ORDER BY to control which rows to return.
    In that case my first reply is valid. Have y look at ROW_NUMBER(), if you're on SQL Server 2005.
  8. carrascojg New Member

    That's right, but the perfomance is a little low. Yes, i have right index.
    But if you compare perfomance between TOP solution and ROW_NUMBER() solution, the execution plan tell me the true.
    Thanks'

Share This Page