Tôi cần phải chọn một số hàng từ bảng thứ hai và nối chúng trong chuỗi được phân cách bằng dấu phẩy. Truy vấn hoạt động tốt ngoại trừ một vấn đề - Nó luôn chọn tất cả các hàng và bỏ qua LIMIT.LIMIT bị bỏ qua trong truy vấn với GROUP_CONCAT
Đây là một phần của truy vấn của tôi mà được chuỗi đó và bỏ qua 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)
Full truy vấn:
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 where slud_data.product_id=t1.product_id and value!='' and display=0 limit 3) text
FROM slud_products t1
WHERE
now() < DATE_ADD(date,INTERVAL +ttl DAY) and activated=1
ORDER BY t1.date desc