SQL - LIMIT query

SELECT * FROM Employees ORDER BY EmployeeID LIMIT(5,3);

I want to select only 3 records that are the 5th, 6th and 7th records in a table called Employees. This Employees table consists of 100 records.

I tried using "LIMIT" function as stated in the code but it was not working - I do not understand where have I gone wrong.

Thanks in advance for helping me out.

2 answers

  • answered 2018-04-17 06:07 Tim Biegeleisen

    The syntax for MySQL's LIMIT is:

    LIMIT offset, count

    where offset means the number of records from the top which you want to skip completely, and count is the total number of records to be returned.

    So if you want 3 records starting from the 5th position, then use this query:

    SELECT *
    FROM Employees
    ORDER BY EmployeeID
    LIMIT 4, 3;


  • answered 2018-04-17 06:26 Faruk Terzi

    You can try this one

    SELECT * FROM employees LIMIT 5, 3;

    and also query below can be help you

    SELECT * FROM employees WHERE id BETWEEN value1 AND value2;