mysql 查询中的 group_concat 提前停止 [英] group_concat in mysql query stops early

查看:33
本文介绍了mysql 查询中的 group_concat 提前停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 mysql 查询中遇到 group_concat 问题:

I have a problem with group_concat in mysql query :

它停在 513 号码上!

It stops on 513 number !

这是正常的查询,它返回 813 行:

This is the normal query and it returns 813 rows :

SELECT * 
FROM survey_votes
WHERE sid =  '4'

现在问题出在这个查询上:

and now the problem is with this query:

SELECT s.*,     
    GROUP_CONCAT(v.oid) AS myoids
    FROM survey s
    LEFT JOIN survey_votes v ON s.sid=v.sid
    WHERE s.sid='4'

这将返回包含最多 513 个字符串的数组 'myoids' 的 1 行.

This returns 1 row containing an array 'myoids' up to 513 strings.

表格'调查'的结构:

sid  int(11)          
stitle   varchar(255)
sdesc    text     
soptions text    
sdate    datetime  
active   int(1)

survey_votes:

survey_votes:

vid int(11) 
sid int(11)     
uid int(11)     
uip varchar(255)    
oid int(11)     
sdate   datetime

myoids 最多只包含 513 行:

myoids only contains upto 513 rows :

Array
(
    [0] => 1
    [1] => 1
    [2] => 3
    .........
    [511] => 1
    [512] => 
)

推荐答案

这是因为 MySQL 截断了 GROUP_CONCAT 一定限制后:

This is because MySQL truncates the result of GROUP_CONCAT after a certain limit:

结果被截断为由group_concat_max_len 系统变量,默认值为1024.

The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024.

尝试增加 的值group_concat_max_len 变量使用 SET 命令:

SET SESSION group_concat_max_len = 1024 * 1024; -- 1MB

这篇关于mysql 查询中的 group_concat 提前停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆