I've just upgraded MySQL to 5.7.17 because of the JSON support. Some changes in the project required this upgrade. Just one SQL Query is not working as expected. I get an error:
ER_WRONG_FIELD_WITH_GROUP
I've googled it, and most answers were: Disable ONLY_FULL_GROUP_BY
in the sql mode. But that's just working around the problem instead of fixing it. Correct me if I'm wrong.
My SQL that is giving problems:
SELECT users.*,
GROUP_CONCAT(d_user_link.public_key ORDER BY d_user_link.id) AS linked_devices,
permission_users.group_id,
permission_users.custom_permissions,
permission_groups.group_name,
permission_groups.group_permissions
FROM users
INNER JOIN permission_users
ON permission_users.user_id = users.id
INNER JOIN permission_groups
ON permission_groups.id = permission_users.group_id
LEFT JOIN d_user_link
ON d_user_link.user_id = users.id
AND d_user_link.disabled = 0
WHERE users.id = ?
GROUP BY users.id
The d_user_link
doesn't have results for every user, because some users can see every device (d_user_link
is device-user-link), or don't have any linked devices.
I hope you can help me with this problem. I couldn't get to an answer by googling it other that disabling ONLY_FULL_GROUP_BY
.
Thanks!