Home > Article > Backend Development > Explanation of SQL TOP clause
SQL TOP plays an important role in advanced operations of the database, and this article will explain it.
TOP clause
The TOP clause is used to specify the number of records to be returned.
The TOP clause is very useful for large tables with thousands of records.
Note: Not all database systems support the TOP clause.
SQL Server syntax:
SELECT TOP number|percent column_name(s)
FROM table_name
MySQL and Oracle The SQL SELECT TOP is equivalent
MySQL Syntax
SELECT column_name(s) FROM table_name LIMIT number
Example
SELECT * FROM Persons LIMIT 5
Oracle Syntax
SELECT column_name(s) FROM table_name WHERE ROWNUM <= number
Example
SELECT * FROM Persons WHERE ROWNUM <= 5
SQL TOP Example
Now, we want to select the first two records from the "Persons" table above.
We can use the following SELECT statement:
SELECT TOP 2 * FROM Persons
This article provides a relevant explanation of the SQL TOP clause. For more learning materials, please pay attention to the php Chinese website.
Related recommendations:
About the analysis of the SQL SELECT DISTINCT statement
Related knowledge about the SQL SELECT statement
The above is the detailed content of Explanation of SQL TOP clause. For more information, please follow other related articles on the PHP Chinese website!