I'm having trouble with this code in Postgres. I'd like to get all fields in the user table, but only group by id. This works well on MySQL and SQLite, but after googling I've found out that this behaviour isn't part of the standard.
SELECT u.*, p.*, count(o.id) AS order_count
FROM shop_order AS o
LEFT JOIN user AS u ON o.user_id = u.id
LEFT JOIN userprofile AS p ON p.user_id = u.id
WHERE o.shop_id = <shop_id>
GROUP BY u.id
(Please note that <shop_id>
is being passed programmatically, so you could just as easily replace it with any integer.)
This is the error I'm getting
column "u.id" must appear in the GROUP BY clause or be used in an aggregate function
I'm an SQL newbie, so be gentle if this is obvious :)