D
D
Donald_Duck2018-06-10 15:02:07
MySQL
Donald_Duck, 2018-06-10 15:02:07

How to group rows in MySQL since version 5.7?

Hello! Since MySQL 5.7 it is no longer possible to make queries like

select `field_1`, `field_2` from `table` group by `group_id`

How to be, for example, if you need to group by one field, but other fields must also be present in the selection? Performing two queries, the first with grouping, and the second pulling up the rest of the fields, taking into account the results of the first one, seems like such a solution ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
retvizan, 2018-06-10
@retvizan

1. плохое решение
set @@sql_mode='only_full_group_by';
2. хорошее - писать запрос в соответствии со стандартом SQL, т.е. использовать групповые функции для полей, которые не перечислены в части group by.
Рекомендую этустатью, там приводится разбор 5ти вариантов с указанием их эффективности.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question