use group by to ensure row count correctness in any case.