0
votes

The following code works fine:

SELECT name, (SELECT count(item_id) FROM bids WHERE item_id = items.id)
FROM items;

However, when I add

SELECT name, (SELECT count(item_id) FROM bids WHERE item_id = items.id)
FROM items
GROUP BY name;

I get ERROR: subquery uses ungrouped column "items.id" from outer query

Can anyone tell me why this is happening? Thanks!

In your second query, should the semi-colon in the second line be there? - Bob Jarvis - Reinstate Monica
No, just edited. Thanks for catching. - J. Doe