I have the following MySQL query:
SELECT SUM(IF(num_content>3,3,num_content))
FROM
(
SELECT DATE(FROM_UNIXTIME(content_timestamp)) as dt, COUNT(id) as num_content
FROM content
WHERE author = 'newbtophp'
GROUP BY DATE(FROM_UNIXTIME(content_timestamp))
)a
Which returns the a count of content (from a specific content author) but with the following restriction => it will only consider a maximum of 3 rows of data per day (using the content_timestamp).
It is working fine, however now I’m wanting to return all ids (do a query then a while loop with mysql_fetch_assoc) which fall under that restriction, I’ve tried the following query:
SELECT id
FROM
(
SELECT DATE(FROM_UNIXTIME(content_timestamp)) as dt, COUNT(id) as num_content, id FROM content
WHERE author = 'newbtophp'
GROUP BY DATE(FROM_UNIXTIME(content_timestamp))
)a
But no luck (as its not returning the ids with the restriction).
The main issue for me is I’m not sure how to integrate the restriction whilst returning the ids.
I appreciate all responses.
There certainly must exist a more efficient solution (JOIN), but the following is readable: