CodeEraFree roadmap

SQL Practice / LIMIT and OFFSET

SQL LIMIT and OFFSET: practice questions with answers

8 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

LIMIT n returns only the first n rows. OFFSET m skips m rows first, which is how pagination works. Always combine them with ORDER BY: without it the database may return the rows in any order, so "the first 10" is not well defined.

LIMIT works in MySQL, MariaDB, PostgreSQL and SQLite. SQL Server uses TOP, and Oracle uses FETCH FIRST (see the TOP and FETCH FIRST practice set).

SELECT columns FROM table_name
ORDER BY column
LIMIT count OFFSET skip;

These questions use the employees table (30 rows). Create it first with the copy-and-paste setup script. Here is the data, so you can check your answers by eye.

See the employees table

Table: employees

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT
1021DavidMillsNULL1998-01-24M2019-12-26IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1023MatthewHill413651998-05-16M2019-05-23IT
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1025MarkWood651201998-10-29M2020-07-30Business Development
1026ElizabethWalker470301998-08-11F2021-06-18NULL
1027BarbaraAndersonNULL1999-12-27F2021-03-14HR
1028JessicaClark638361998-01-24F2021-05-23IT
1029NancyCole636692000-01-26F2019-12-26Finance
1030JoeBrooks440001999-08-05M2021-03-09Business Development

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Return all columns from the employees table, but show only the first 10 rows.

Show the answer and the output
SELECT * FROM employees ORDER BY emp_no LIMIT 10;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT

Different from the PDF: Added ORDER BY emp_no. Without it the "first 10" rows are not guaranteed.

Question 2Return the next 10 rows (rows with emp_no 1011 to 1020).

Show the answer and the output
SELECT * FROM employees ORDER BY emp_no LIMIT 10 OFFSET 10;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT

OFFSET 10 skips the first 10 rows. Page 3 would be OFFSET 20.

Question 3Fetch emp_no, first name, last name and joining date of the 6 employees who joined most recently.

Show the answer and the output
SELECT emp_no, first_name, last_name, joining_date
FROM employees
ORDER BY joining_date DESC
LIMIT 6;

Output

emp_nofirst_namelast_namejoining_date
1020DanielElliott2023-01-08
1006MichaelWatts2022-06-09
1014ThomasRyan2022-03-02
1017NancyParker2022-01-09
1007DavidMills2021-10-17
1009LindaPotter2021-08-07

Question 4Retrieve all the details of the 2 youngest employees.

Show the answer and the output
SELECT * FROM employees ORDER BY birth_date DESC LIMIT 2;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1029NancyCole636692000-01-26F2019-12-26Finance

The youngest people have the latest birth dates, so sort by birth_date DESC.

Question 5Retrieve all the details of the 3 eldest male employees.

Show the answer and the output
SELECT * FROM employees WHERE gender = 'M' ORDER BY birth_date LIMIT 3;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1010RichardMartin256001996-08-07M2021-03-23IT
1014ThomasRyan236761996-10-12M2022-03-02IT

Question 6Retrieve emp_no, first name and salary of the 3 highest paid employees.

Show the answer and the output
SELECT emp_no, first_name, salary
FROM employees
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 3;

Output

emp_nofirst_namesalary
1002Robert69410
1017Nancy66900
1025Mark65120

Question 7Retrieve all the details of the 3 lowest paid employees of the IT department.

Show the answer and the output
SELECT * FROM employees
WHERE salary IS NOT NULL AND department = 'IT'
ORDER BY salary
LIMIT 3;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1014ThomasRyan236761996-10-12M2022-03-02IT
1010RichardMartin256001996-08-07M2021-03-23IT
1007DavidMills394001998-04-26M2021-10-17IT

salary IS NOT NULL matters here: in ascending order MySQL would otherwise put NULL salaries first.

Question 8Retrieve the first three employees whose first name starts with 'J', in alphabetical order of first name.

Show the answer and the output
SELECT * FROM employees WHERE first_name LIKE 'J%' ORDER BY first_name LIMIT 3;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1005JenniferGill489411996-06-05F2019-06-28Marketing
1016JessicaClarkNULL2000-01-25F2020-01-24IT

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.