SELECT name FROM mydb ORDER BY score DESC LIMIT 10;
The query above will return the first 10 ranks.
How to modify the LIMIT
, or maybe is there another syntax to query the 10th rank through the 20th rank?
Limit Data Selections From a MySQL Database Assume we wish to select all records from 1 - 30 (inclusive) from a table called "Orders". The SQL query would then look like this: $sql = "SELECT * FROM Orders LIMIT 30"; When the SQL query above is run, it will return the first 30 records.
The SQL SELECT LIMIT statement is used to retrieve records from one or more tables in a database and limit the number of records returned based on a limit value. TIP: SELECT LIMIT is not supported in all SQL databases. For databases such as SQL Server or MSAccess, use the SELECT TOP statement to limit your results.
In MySQL the LIMIT clause is used with the SELECT statement to restrict the number of rows in the result set. The Limit Clause accepts one or two arguments which are offset and count. The value of both the parameters can be zero or positive integers.
The limit keyword is used to limit the number of rows returned in a query result. “SELECT {fieldname(s) | *} FROM tableName(s)” is the SELECT statement containing the fields that we would like to return in our query. “[WHERE condition]” is optional but when supplied, can be used to specify a filter on the result set.
You should use:
SELECT name FROM mydb ORDER BY score DESC LIMIT 10,10;
http://dev.mysql.com/doc/refman/5.5/en/select.html
The two arguments 10,10 are (Offset, Limit) so this will retrieve rows 11-20.
9,11 Would be required to grab the 10th - 20th rank.
Use offset
to clarify the query.
SELECT name FROM mydb ORDER BY score DESC LIMIT 10 OFFSET 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With