I have a query that worked fine on MySQL and now doesn't on PostgreSQL This is the query:
SELECT "users".*
FROM "users"
JOIN "favorites" ON "favorites"."user_id" = "users"."id"
WHERE users.id NOT IN (2)
AND favorites.favoritable_id IN (1)
GROUP BY favorites.user_id
ORDER BY RANDOM()
LIMIT 5
This is the error:
column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
I have looked up this error but couldn't really find out what I must to do fix this.