SQL Select TOP & more

1. Select Top

SQL provides several ways to limit the number of rows returned in a query result, including:

Syntax:

example:

2. LIMIT Clause (MySQL, PostgreSQL)

syntax:

example:

3. FETCH FIRST Clause (DB2, Oracle)

syntax:

example:

4. ROWNUM Clause (Oracle)

syntax:

SELECT [column1, column2, …]
FROM (
SELECT [column1, column2, …], ROWNUM as row_number
FROM table_name
)
WHERE row_number <= N;

example:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top