SELECT p.id, p.name, ...
FROM programmes p
LEFT OUTER JOIN notes n
ON (n.id_prgm=p.id AND ...)
WHERE ...
GROUP BY p.id WITH ROLLUP
You will have the count per program and then a NULL, TOTAL COUNT row after that.
Also, take care of the following:
When you use ROLLUP, you cannot also use an ORDER BY clause to sort
the results. In other words, ROLLUP and ORDER BY are mutually
exclusive. However, you still have some control over sort order. GROUP
BY in MySQL sorts results, and you can use explicit ASC and DESC
keywords with columns named in the GROUP BY list to specify sort order
for individual columns. (The higher-level summary rows added by ROLLUP
still appear after the rows from which they are calculated, regardless
of the sort order.)
If you want the total count shown in each row, remove the group by:
SELECT p.id, p.name, COUNT(*)
FROM programmes p
LEFT OUTER JOIN notes n
ON (n.id_prgm=p.id AND ...)
WHERE ...
ORDER BY ...
If you want the count to appear for each record but keeping the group by, do the following:
SELECT t.*, COUNT(*) FROM (
SELECT p.id, p.name, ...
FROM programmes p
LEFT OUTER JOIN notes n
ON (n.id_prgm=p.id AND ...)
WHERE ...
GROUP BY ...
ORDER BY ...
) t
The limit clause is not supported within a subquery though, you'll have to find something else.
I think you want to DISTINCT, not GROUP BY. This is not the same thing and should not be mixed up. See my answer to this question for further informations.