Home > Backend Development > PHP Tutorial > Explanation of SQL TOP clause

Explanation of SQL TOP clause

jacklove
Release: 2023-03-25 15:16:02
Original
2501 people have browsed it

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
Copy after login

Example

SELECT *
FROM Persons
LIMIT 5
Copy after login

Oracle Syntax

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number
Copy after login

Example

SELECT *
FROM Persons
WHERE ROWNUM <= 5
Copy after login

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
Copy after login

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

How to useJSON

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template