SELECT TOP

SQL SELECT TOP Keyword

The SELECT TOP command is used in SQL Server to return only the top N rows in a result set.

Note:

Tutorials dojo strip
  • SQL Server uses SELECT TOP
  • MySQL and SQLite use LIMIT
  • Oracle uses ROWNUM

SQL SELECT TOP Syntax

SELECT TOP number column1, column2, ...
FROM table_name;

SQL SELECT TOP Example

SELECT TOP 3 *
FROM Patients;

Note: This code does not work in TechKubo playground. SQLite does not support SELECT TOP. Use LIMIT instead.

SQL SELECT TOP Equivalent Using LIMIT Example

SELECT *
FROM Patients
LIMIT 3;

SQL SELECT TOP Equivalent Using ROWNUM (Oracle Only)

SELECT *
FROM Patients
WHERE ROWNUM <= 3;

Note: This code does not work in TechKubo playground. SQLite does not support ROWNUM.

SQL SELECT TOP Labs

Tutorials dojo strip
Tutorials dojo strip
Scroll to Top