lib.php: fix bug with missing u.id in GROUP BY clause