I have this query:
select distinct user_id,
if((user_A_id = 2 or user_B_id = 2) and connected = 1, 1, 0) mutualConnections,
if(user_A_id = 2 and connected = 0, 1, 0) requestsUserSent,
if(user_B_id = 2 and connected = 0, 1, 0) requestsUserReceived,
if((user_A_id != 2 and user_B_id != 2) or (user_A_id is null and user_B_id is null), 1, 0) notConnected
from Connections
right join user_configuration on(user_id = user_A_id or user_id = user_B_id)
group by user_id having user_id != 2;
When I run it in my local DB, it works just fine. I uploaded my DB to AWS EC2 machine, and when i run this query I get the following error:
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'users_db.Connections.user_A_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
I added this command in My SQL server: SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); and the output of the query is not right. I read in other post that when I disable ONLY_FULL_GROUP_BY, the server is free to choose any value from each group from group by clause.
How can I fix the query or the error?