I think you should count the results with FOUND_ROWS() and SQL_CALC_FOUND_ROWS. You'll need two queries: select
, group_by
, etc. You'll add a plus select: SQL_CALC_FOUND_ROWS user_id
. After this query run a query: SELECT FOUND_ROWS()
. This will return the desired number.