두 번째 테이블에서 일부 행을 선택하고 쉼표로 구분 된 문자열로 연결해야합니다. 한 가지 문제를 제외하고 쿼리가 잘 작동합니다. 항상 모든 행을 선택하고 LIMIT를 무시합니다.GROUP_CONCAT을 사용하여 쿼리에서 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)
전체 쿼리
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