我有两张简单的桌子
table1 table2
| id | name | | id | name |
| 1 | name_1 | | 1 | name-1 |
| 2 | name_2 | | 2 | name-2 |
| 3 | name_3 | | 3 | name-3 |
................... ...................
100 row 10000 row我把这些桌子上的名字像这样
select
(
select group_concat(name) from table1
) as t1
,
(
select group_concat(name) from table2
) as t2但我只想将行结果限制为50行
如何有效地做到这一点。
我得到的结果是这样的
t1: name_1, name_2, name_3 . . . , name_100
t2: name-1, name-2, name-3 . . . , name-10000但我只想在50号停下来。
发布于 2018-10-29 14:45:54
在导出表中,首先只能获得50行。现在,您可以将此结果集用于Group_concat()。
但是,请注意文档中的这一点
结果被截断到group_concat_max_len系统变量给出的最大长度,该变量的默认值为1024。虽然返回值的有效最大长度受max_allowed_packet值的约束,但可以将其设置为更高的值。
50值很可能生成一个非常长的字符串(超过1024个字符)。如果在运行查询之前不增加group_concat_max_len系统变量的值,则结果将被截断:
-- increasing group_concat_max_len for this session
SET SESSION group_concat_max_len = @@max_allowed_packet;
SELECT GROUP_CONCAT(dt.name ORDER BY dt.id)
FROM
(
SELECT id, name
FROM table1
ORDER BY id LIMIT 50
) AS dthttps://stackoverflow.com/questions/53047938
复制相似问题