0
    #1055 - Expression #3 of 

SELECT list is not in GROUP BY clause and contains nonaggregated column 'prorab.category_letter_master.category_letter_id' 

which is not functionally dependent on columns in 

GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Here is how it works.

SELECT master_user.master_id,
masters.specialization,

COUNT(*) FROM master_user

LEFT JOIN masters ON master_user.master_id = masters.id
LEFT JOIN category_letter_master ON category_letter_master.master_id  = master_user.master_id 

WHERE city_id = 4019
GROUP BY master_user.master_id

And if you add a category_letter_master.category_letter_id, it does not work

SELECT master_user.master_id,
masters.specialization,
category_letter_master.category_letter_id, 
COUNT(*) FROM master_user

LEFT JOIN masters ON master_user.master_id = masters.id
LEFT JOIN category_letter_master ON category_letter_master.master_id  = master_user.master_id 

WHERE city_id = 4019
GROUP BY master_user.master_id

Displays error 1055

Added 3 tables

Added 3 tables
Added 3 tables
Added 3 tables

////////////////////////////////////////

    --
-- Структура таблицы `masters`
--

CREATE TABLE `masters` (
  `id` int(10) UNSIGNED NOT NULL,
  `specialization` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Дамп данных таблицы `masters`
--

INSERT INTO `masters` (`id`, `specialization`) VALUES
(1, 'Алмазная резка'),
(2, 'Гипсокартон'),
(3, 'Двери'),
(4, 'Пол'),
(5, 'Потолок'),
(7, 'Кладка');

--
-- Индексы сохранённых таблиц
--

--
-- Индексы таблицы `masters`
--
ALTER TABLE `masters`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT для сохранённых таблиц
--

--
-- AUTO_INCREMENT для таблицы `masters`
--
ALTER TABLE `masters`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
COMMIT;

/////////////////////////////////////

--
-- Структура таблицы `category_letter_master`
--

CREATE TABLE `category_letter_master` (
  `id` int(10) UNSIGNED NOT NULL,
  `category_letter_id` int(11) NOT NULL,
  `master_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Дамп данных таблицы `category_letter_master`
--

INSERT INTO `category_letter_master` (`id`, `category_letter_id`, `master_id`) VALUES
(1, 1, 1),
(2, 4, 2),
(3, 5, 3),
(4, 17, 4),
(5, 17, 5),
(7, 12, 7);

--
-- Индексы сохранённых таблиц
--

--
-- Индексы таблицы `category_letter_master`
--
ALTER TABLE `category_letter_master`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT для сохранённых таблиц
--

--
-- AUTO_INCREMENT для таблицы `category_letter_master`
--
ALTER TABLE `category_letter_master`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
COMMIT;

////////////////////////////////////////////////////

CREATE TABLE `master_user` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(11) NOT NULL,
  `master_id` int(11) NOT NULL,
  `city_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Дамп данных таблицы `master_user`
--

INSERT INTO `master_user` (`id`, `user_id`, `master_id`, `city_id`) VALUES
(15, 16, 3, 4019),
(18, 16, 5, 4019),
(19, 16, 4, 4019),
(20, 16, 2, 4019),
(21, 17, 4, 4019),
(22, 17, 2, 4400);

--
-- Индексы сохранённых таблиц
--

--
-- Индексы таблицы `master_user`
--
ALTER TABLE `master_user`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT для сохранённых таблиц
--

--
-- AUTO_INCREMENT для таблицы `master_user`
--
ALTER TABLE `master_user`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;
COMMIT;
DivMan
  • 131
  • 1
  • 8
  • Add the table (or query to create it) and some inserts so we can figure out! – M.K Oct 19 '18 at 10:27
  • 3
    MySQL is right. You should not have unaggregated columns in the `SELECT` that are not in the `GROUP BY`. If you want to do something in particular, ask a *new* question with sample data, desired results, and an explanation of what you want to do. – Gordon Linoff Oct 19 '18 at 10:38
  • @GordonLinoff Added 3 tables – DivMan Oct 19 '18 at 10:48
  • @HoneyBadger #1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'prorab.category_letter_master.category_letter_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by – DivMan Oct 19 '18 at 10:52

0 Answers0