SQLSTATE [42000]:语法错误或访问冲突:1055列不在GROUP BY中

时间:2016-11-07 16:41:22

标签: php mysql laravel-5 laravel-query-builder

我有一个查询在mysql客户端和phpmyadmin上工作得很好,我的查询是:

select members.m_id, members.m_reach, members.m_member_num_groups, members.m_name, groups.tr_cat,
    groups.tr_id, group_categories.tc_id, group_categories.tc_name,group_members.tm_owner_id,
    group_members.tm_group_id from members join group_members on group_members.tm_owner_id = members.m_id
    join groups on groups.tr_id = group_members.tm_owner_id
    join group_categories on group.tr_cat = group_categories.tc_id
    group by members.m_id
    order by members.m_reach DESC limit 5

但是当我用laravel DB :: select尝试时,我得到错误:

SQLSTATE[42000]: Syntax error or access violation: 1055 'muzikal.members.m_reach' isn't in GROUP BY 

这是我的laravel查询:

$influencers = \DB::table('members')
        ->join('group_members', 'group_members.tm_owner_id', '=', 'members.m_id')
        ->join('groups', 'groups.tr_id', '=', 'group_members.tm_owner_id')
        ->join('group_categories', 'groups.tr_cat', '=', 'group_categories.tc_id')
        ->select('members.m_id', 'members.m_reach', 'members.m_member_num_groups', 'members.m_name', 'groups.tr_cat',
                  'groups.tr_id', 'group_categories.tc_id', 'group_categories.tc_name','group_members.tm_owner_id',
                  'group_members.tm_tribe_id')
        ->orderBy('members.m_reach', 'DESC')
        ->groupBy('members.m_id')
        /**->distinct('m_id') tried this also **/
        ->limit('5')
        ->get();

我见过很多人提出同样的问题,但无法得到正确答案

0 个答案:

没有答案