SQL Select Limit Statement

Select Limit statement is used to retrieve the limit records from the table.

Syntax:-


SELECT * FROM table_name LIMIT limit_number

Note:- limit_number is a numeric value.

Example:-
We have an employees table which has 5 records.


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | John       | Tailor    | john@abc.com   | California |
|  2 | Rom        | Tailor    | rom@abc.com    | California |
|  3 | Andrew     | Symonds   | andrew@abc.com | Sydney     |
|  4 | Miacle     | clerk     | miacle@abc.com | sydney     |
|  5 | Sachin     | Tendulkar | sachin@abc.com | Mumbai     |

Now, we want to get two records from employees table


SELECT * FROM employees LIMIT 2

Output:-


| id | first_name | last_name | email        | address    |
+----+------------+-----------+--------------+------------+
|  1 | John       | Tailor    | john@abc.com | California |
|  2 | Rom        | Tailor    | rom@abc.com  | California |
+----+------------+-----------+--------------+------------+

SQL Select Limit Statement – Interview Questions

Q 1: What is LIMIT used for?
Ans: LIMIT restricts the number of rows returned.
Q 2: Syntax of LIMIT?
Ans: SELECT * FROM table LIMIT 5;
Q 3: Is LIMIT supported by all databases?
Ans: Most support it; SQL Server uses TOP.
Q 4: Can LIMIT be combined with OFFSET?
Ans: Yes, for pagination.
Q 5: Does LIMIT affect database data?
Ans: No, it only limits output.

SQL Select Limit Statement – Objective Questions (MCQs)

Q1. Which clause is used to limit the number of records returned?






Q2. What does LIMIT 5 do?






Q3. Which database uses the LIMIT clause?






Q4. Which keyword is used instead of LIMIT in SQL Server?






Q5. What is the correct syntax to skip 5 records and fetch 10 records?






Related SQL Select Limit Statement Topics