select works.*, category.name as category
from work_category inner join works
on works.id = work_category.work_id
inner join category
on category.id = work_category.category_id
Результат запроса такой:
Как можно объединять идентичные строки чтобы поле category было примерно так - "Верстка, программирование" ?
select works.*, GROUP_CONCAT(category.name SEPARATOR ',') as category
from work_category inner join works
on works.id = work_category.work_id
inner join category
on category.id = work_category.category_id
GROUP BY works.id, name;
Алексей Т, #1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'nor1m-app.works.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
select works.*, GROUP_CONCAT(category.name SEPARATOR ',') as category
from work_category inner join works
on works.id = work_category.work_id
inner join category
on category.id = work_category.category_id
GROUP BY works.id, name