JN_newbie JN_newbie - 4 months ago 35
SQL Question

ER_WRONG_FIELD_WITH_GROUP: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated

I am trying to run this query but it throws an error

ER_WRONG_FIELD_WITH_GROUP: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated

Below is the query which I am using in my code.

"select created_at from user where username = '" + id + "' group by DATE(created_at)"

Answer

You don't need to change the mode. You can try changing it and checking. Restart MYSQL.

But, below should work fine.

SELECT DATE(created_at) 
FROM user 
WHERE username = '" + id + "' 
GROUP BY DATE(created_at)