MySQL - Top
The TOP clause is used to specify the number of records to return. The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.
MySQL Top Syntax
SELECT column_name(s) FROM table_name LIMIT number
MySQL Top Example
SELECT *FROM Persons LIMIT 5
The "persons" table:
| ID | First Name | Last Name | Address |
| 1 | Putu | Sanjaya | Denpasar |
| 2 | Made | Sanjaya | Sanur |
| 3 | Haru | Sanjaya | Gianyar |
Now we want to select only the two first records in the table above. We use the following SELECT statement:
SELECT *FROM Persons LIMIT 2
The result-set will look like this:
| ID | First Name | Last Name | Address |
| 1 | Putu | Sanjaya | Denpasar |
| 2 | Made | Sanjaya | Sanur |