You cannot achieve this with the simple WHERE, as it COUNT()is a group function, and you cannot use plain HAVING, since it will group the lines into one.
Instead, you will have to evaluate the total score in a separate request and combine it, for example CROSS JOIN:
SELECT
iv6_posts.*
FROM
iv6_posts
CROSS JOIN
(
SELECT
COUNT(1) AS c
FROM
iv6_posts
) AS init
WHERE
c<5
Check the fiddle .
source
share