Alternative to TOP Keyword in MySQL
In MySQL, the TOP keyword, familiar from SQL Server, is not available. However, you can achieve the same functionality using other methods.
Ordering and Limiting Results
The alternative in MySQL is to use the ORDER BY and LIMIT clauses in combination. For example, to retrieve the top 10 rows based on field1 in ascending order:
SELECT field1, field2 FROM myTable ORDER BY field1 ASC LIMIT 10;
By adjusting the LIMIT clause, you can retrieve any number of top rows as needed.
The above is the detailed content of How to Get the Top N Rows in MySQL Without the TOP Keyword?. For more information, please follow other related articles on the PHP Chinese website!