0

I am not a DBA and I inherited this query and i'm not quite sure why I'm getting a sql_mode=only_full_group_by error. Especially since the error is talking about result.fullURL and i don't see that in the query. Could someone please explain this to me?

Query

SELECT *
FROM (
    SELECT content.*, content.navigationOrder AS sortOrder
    FROM LB_Content AS content
    INNER JOIN LB_Content AS other ON content.contentSectionId = other.contentSectionId
    WHERE other.fullURL = '/index'
    AND content.contentSlug <> 'index'
    GROUP BY content.contentId
    UNION
    SELECT content.*, query.sectionOrder AS sortOrder
    FROM LB_Content AS content, (
        SELECT section.*
        FROM LB_ContentSections AS section
        INNER JOIN LB_Content AS other ON section.parentContentSectionId = other.contentSectionId
        WHERE other.fullURL = '/index'
    ) AS query
    WHERE content.contentSectionId = query.contentSectionId
    AND content.contentSlug = 'index'
) as result,
LB_ContentTypes AS types
WHERE result.showInNavigation = 1
AND result.status = 1
AND result.published = 1
AND result.contentTypeId = types.contentTypeId
AND types.useOption = 1
GROUP BY result.contentId
ORDER BY result.sortOrder ASC

Error output

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'result.fullURL' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Thanks for any help!

4

1 回答 1

0

“仅完整分组依据”意味着您的聚合查询必须对结果中的所有非聚合字段进行分组。它们是否“隐藏”在 中并不重要*,这些字段也必须分组。

这个查询甚至不应该开始分组;没有使用聚合函数。如果“仅完整分组依据”不是当前设置,则此查询将是“给我一个有效的随机结果,为每个 contentId 传递 where 条件”。

于 2018-05-04T20:18:12.537 回答