I find that MySQL returns a
Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'
error if I put SQL_CALC_FOUND_ROWS in a subquery
SELECT
*
FROM
(
SELECT SQL_CALC_FOUND_ROWS * FROM test_table
) as T1
Is there a workaround for this? or am I just implementing it incorrectly?
EDIT: There is a reason why I need to make T1 a subquery in case anyone is wondering.
It seems like you’re using it incorrectly. The
SQL_CALC_ROWS_FOUNDseems to only apply to outer queries. I’m not sure if this would fit your use case, or if you have additionalWHEREs in your outer query, but you may be able to do something like this:The
FOUND_ROWS()function will give you the total number of rows found before anyLIMITs are applied. For more onFOUND_ROWS()check here.