Search code examples
mysqloffsetlimiting

Reading Data from Databases with SQL, Limiting the Result Set


I am having a hard time understanding the limit and offset parts of MYSQL. Could someone use this example "Get the 101st to 200th actor from the actors table. (No need to use any ordering)." and explain to me how this would work and the math behind it? Thanks!


Solution

  • `SELECT * FROM table limit 100, 100` -- get 100 records from row 101 (101 - 200)
    

    This will give you 50 records after 101:

    `SELECT * FROM table limit 100, 50` -- get 50 records from row 101 (101 - 150)
    

    For more details, you can see the syntax and usage for limit here.