Skip to main content
deleted 30 characters in body
Source Link
Vlad Mihalcea
  • 155.9k
  • 85
  • 599
  • 984

As I explained in this article, theThe syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL query result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUMROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 

As I explained in this article, the syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL query result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 

The syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL query result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 
deleted 86 characters in body
Source Link
marc_s
  • 759.9k
  • 186
  • 1.4k
  • 1.5k

As I explained in this article, the syntax for limiting the result set size depends on the database you are using.

SQL Standard

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL queyrquery result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 

As I explained in this article, the syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL queyr result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 

As I explained in this article, the syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL query result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50 
Source Link
Vlad Mihalcea
  • 155.9k
  • 85
  • 599
  • 984

As I explained in this article, the syntax for limiting the result set size depends on the database you are using.

SQL Standard

The SQL:2008 standard defines the following syntax for limiting a SQL queyr result set:

SELECT title FROM post ORDER BY id DESC FETCH FIRST 50 ROWS ONLY 

The SQL:2008 Top-N records clause is supported in Oracle since 12c, SQL Server since 2012, and PostgreSQL since 8.4.

SQL Server

While SQL Server supports the SQL:2008 Top-N standard syntax, you need to provide the OFFSET clause as well:

SELECT title FROM post ORDER BY id DESC OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

On older SQL Server versions, you can use TOP:

SELECT TOP 50 title FROM post ORDER BY id DESC 

Oracle 11g and older versions

Prior to version 12c, to fetch the Top-N records, you had to use a derived table and the ROWNUM pseudocolumn:

SELECT * FROM ( SELECT title FROM post ORDER BY id DESC ) WHERE ROWNUM <= 50 

MySQL and PostgreSQL 8.3 or older

Traditionally, MySQL and PostgreSQL use the LIMIT clause to restrict the result set to the Top-N records:

SELECT title FROM post ORDER BY id DESC LIMIT 50