This is how I have my current query setup:
SELECT * , (
SELECT COUNT( * )
FROM paintings
WHERE id > 4000
) AS total
FROM paintings
WHERE id > 4000
LIMIT 0 , 30
Everything works fine if I separate the queries but if I keep it like this the pagination shows 1 id missing at the end of the page.
What would be a better option for selecting count that doesn’t return on each row but for the whole?
Ex: this is what I currently get if I pass that in mysql:
> +--------+------------+--------+ > | id | title | count | > +--------+------------+--------+ > | 2345 | water | 25 | > | 2346 | bread | 25 | > | 2347 | coke | 25 | > | 2348 | beer | 25 | > | 2349 | oranges | 25 | > +--------+------------+--------+
Cheers!
Addition to what genesis posted. Still 2 queries but a little cleaner: