
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 0.49 KB | hits: 10 | expires: Never
postgreSQL select additional columns that aren't used in aggregate function
PGError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
PGError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
SELECT users.*, a.num_deals FROM users, (
SELECT deal.id as dealid, COUNT(deals.id) AS num_deals
FROM deals
GROUP BY deal.id
) a where users.id = a.dealid
ORDER BY a.num_deals DESC
LIMIT 5