I have the following tables:
categories
|------|--------|
| id | name |
|------|--------|
| 1 | c1 |
|------|--------|
| 2 | c2 |
|------|--------|
| 3 | c3 |
|------|--------|
items
|------|---------|--------|-------------|
| id | catid | name | modified_by |
|------|---------|--------|-------------|
| 1 | 1 | i1 | juan |
|------|---------|--------|-------------|
| 2 | 1 | i2 | pedro |
|------|---------|--------|-------------|
| 3 | 2 | i3 | pedro |
|------|---------|--------|-------------|
| 4 | 2 | i4 | josé |
|------|---------|--------|-------------|
| 5 | 3 | i5 | pedro |
|------|---------|--------|-------------|
Y I execute the following query:
SELECT c.id, c.name, COUNT(i.id) AS countid
FROM categories AS c
INNER JOIN items AS i ON i.catid = c.id
WHERE c.id IN (1,2,3) GROUP BY i.catid
What I want is to group the number of IDs that each category has when making the count of the items in that category, but I get the following error
# 1055 - Expression # 4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db.i.modified_by' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode = only_full_group_by
If I remove the modified_by
attribute in select the error disappears but I want to keep it. How can I solve this?