Reputation: 2371
I write query like this:
SELECT name, class, period FROM subject
WHERE organization IN (?,?,?,?,?,?,?,?)
GROUP BY class, period
But, it causing error like this:
Error 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'bsi.subject.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
I found solving from this. But, I am not so sure it safe. I am database junior. Is it safe? There is another solution without changing the sql mode setting?
I also found this solution. If column name
not necessary, just simply remove it. But, I consider to add it to reuseable code.
Upvotes: 0
Views: 292
Reputation: 49375
Every column in the Select statements has to be in the GROUP BY
or have aN Aggregation function
like
SELECT GROUP_CONCAT( DISTINCT name) As name, class, period
FROM subject
WHERE organization IN (?,?,?,?,?,?,?,?)
GROUP BY class, period
this would add all names from one period and class as a comma seperated strntg
Upvotes: 1