What would be the best way to return the quantity of groups? Nothing special about my schema; table2 includes a FK referencing table1. The following seems to work. Any problems with it? Any better ways? Thanks
SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM table1 AS t1
INNER JOIN table2 AS t2 ON t2.t1_id=t1.id
WHERE t1.x=1 AND t2.y=1
GROUP BY t2.z
) AS grouping
No, your solution is fine.
Another way would be
This will also include NULLs.
From the manual: