mysql has a limit clause you can use to get a certain row # within your query.
Do note that the order rows are stored in a table isn't guaranteed to be forever. It's more useful when doing paging because you have an order by clause in the query.
With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
And use the LIMIT clause, as Jeanne says, to fetch a certain number of ordered rows at a time.
Jeanne Boyarsky wrote:Almost.
This won't compile as rs.next() returns a boolean to say whether there are any rows returned.
Since there will always be one row (and one column) returned for a count, you use
If you are simply checking whether a row exists, and you don't actually want any data from the row, then you could just do "SELECT 1 FROM...". This will return a 1 as soon as a row is found, so it may be quicker than "SELECT COUNT(*)..." which always has to search the whole table (or index) to get the total count, even if there's only one matching row. If you get anything in your result set, you know a matching row was found. If the result set is empty, then you know there is no matching record.