I have a table containing records that are added monthly. I group them by month and output total counts per month. As the time goes on I'd like to be able to display only the most recent 5 months' data.
So, I'd like to limit my output results to the latest 5. Limit 5 would give me first 5... Not sure how to do that. Shall i get the numeric value of the current month and count backwards somehow? What about the year change?
Here's what I've got so far:
$m = $db->get_results ("
SELECT COUNT(t1.ads_company) AS coCOUNT,
t1.ads_issue, t1.ads_product, t1.ads_company,
t2.issue_id,
YEAR( t2.issue_date ) as yr,
MONTH( t2.issue_date ) as mo
FROM t1
LEFT JOIN t2 ON ( t1.ads_issue = t2.issue_id )
WHERE t1.ads_company = 100
GROUP BY yr, mo
ORDER BY mo ASC ");