Is it possible to let MySQL LIMIT have an offset of the total number of rows divided in 2, so that the query would look something like this:
SELECT * FROM test LIMIT COUNT(*) / 2, 5
Where 5 is just a number.
Using LIMIT you will not limit the count or sum but only the returned rows. So your query will return n rows as stated in your LIMIT clause. And since your query actually returns only one row, applying a (non-zero) limit has no effect on the 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 MySQL LIMIT ClauseThe LIMIT clause is used to specify the number of records to return. The LIMIT clause is useful on large tables with thousands of records. Returning a large number of records can impact performance.
To limit the number of rows/records a SELECT query can fetch append your SQL Query with LIMIT modifier and the syntax of the SQL Query is given below: your_sql_query LIMIT number_of_records; If the number of records in the database for the query is less than the specified, then all those records would be fetched.
It is not possible.
From the documentation:
Expressions can be used at several points in SQL statements, such as in the ORDER BY or HAVING clauses of SELECT statements, in the WHERE clause of a SELECT, DELETE, or UPDATE statement, or in SET statements.
Also from the SELECT documentation:
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).
You will have to do two queries--one to count, the other to limit.
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