我需要从第二个表中选择一些行,并用逗号分隔的字符串连接它们.除了一个问题之外,查询工作正常 - 它总是选择所有行并忽略LIMIT.
这是我的查询的一部分,它获取该字符串并忽略LIMIT:
select
group_concat(value order by `order` asc SEPARATOR ', ')
from slud_data
left join slud_types on slud_types.type_id=slud_data.type_id
where slud_data.product_id=18 and value!='' and display=0 limit 3;
// Result:
+---------------------------------------------------------+
| group_concat(value order by `order` asc SEPARATOR ', ') |
+---------------------------------------------------------+
| GA-XXXX, Bentley, CONTINENTAL FLYING SPUR, 2006 |
+---------------------------------------------------------+
// Expected result: (only 3 comma-separated records, not 4)
Run Code Online (Sandbox Code Playgroud)
完整查询:
SELECT *,product_id id,
(select group_concat(value order by `order` asc SEPARATOR ', ') from slud_data left join slud_types on slud_types.type_id=slud_data.type_id …
Run Code Online (Sandbox Code Playgroud)