我有2个表,想要通过逗号分隔来获取所有类别。
SELECT object_id, meta_value, name, event_level, event_temp_id FROM
wp_em_meta, wp_terms, wp_em_events WHERE wp_em_meta.meta_key = 'category-image'
AND wp_em_meta.object_id IN ($eventtid) AND wp_em_meta.object_id = wp_terms.term_id
AND wp_em_meta.object_id = wp_em_events.event_temp_id
例如:
表1
在附加的图像中,我想以
的形式获取结果答案 0 :(得分:1)
您可以在MySQL中使用GROUP_CONCAT()功能
SELECT object_id,
GROUP_CONCAT(event_level) as meta_value,
name, event_level, event_temp_id FROM
wp_em_meta, wp_terms, wp_em_events
WHERE wp_em_meta.meta_key = 'category-image'
AND wp_em_meta.object_id IN ($eventtid) AND wp_em_meta.object_id = wp_terms.term_id
AND wp_em_meta.object_id = wp_em_events.event_temp_id
GROUP BY object_id