Group by gives error as if the column does not exist even though there is a column

Asked 2 years ago, Updated 2 years ago, 45 views

When I ran SQL below, I got the following message:
The foods table has an id (primary key).

Displayed messages:

Expression#13 of SELECT list is not in GROUP BY cause and containers nonaggregated column'konondate.foods_ingredients.id' which is not functionally dependent on columns in GROUP BY cause; this is incompatible with sql_mode=only_full_group
Expression #13 of SELECT list is not in GROUP BY claim and containments nonaggregated column'kondate.foods_ingredients.id' which is not functionally dependent on columns in GROUP BY cause; this is incompatible with sql_mode=only_full_group_by

SQL queries:

 select * from `foods` left join `foods_ingredients` on `foods`.`id`=`foods_ingredients`.`food_id`left join
`ingredients` on `foods_ingredients`.`ingredients_id`=`ingredients`.`id`left join`ingredients_allegies` on
`foods_ingredients`.`ingredient_id`=`ingredients_allegies`.`allegy_id`where(`category_type_id`=4) and
`ingredients_allegies`.`allegy_id`not in (5) and `event_month`is null group by `foods`.`id`

mysql

2022-09-30 16:07

1 Answers

I think I misread the error in English.


Not the error foods.id is missing. SEThe SELECT column contains columns ('kondate.foods_ingredients.id') that are not aggregated by GroupBy.
error.

You are trying to display columns that are aggregated but not aggregated when extracting.
Specifically
We are aggregating with foods.id but SELECT is trying to display all of them as *.
For example, 'foods_ingredients.id' cannot be determined by the table side.

Basically, the items that you can enumerate in SELECT during aggregation are the columns that you are aggregating (here foods.id) or the aggregation function.

Think again about what tables you want to view and try to assemble SQL.


2022-09-30 16:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.