I have the following query to MySQL database:
SELECT inboxes.*
, count(inboxes.conv) AS times
, max(created_at) AS created_at
FROM `inboxes`
WHERE to_user = 2
OR account_id = 2
GROUP BY conv
ORDER BY id DESC
This query works on my localhost, but if I deploy it to Heroku, I’ll get this error:
PGError: ERROR: column "inboxes.id" must appear in the GROUP BY clause or
be used in an aggregate function
You need to specify all fields in
GROUP BY, which you wanna select, ie:SELECT inboxes.id, count(inboxes.conv) AS times, max(created_at) as created_at FROMinboxesWHERE (to_user = 2 OR account_id = 2) GROUP BY inboxes.id, conv ORDER BY inboxes.id DESC