0
當我火了下面的查詢,我得到我需要通過event.id分組的結果:MySQL的檢索多對多行
SELECT events.id AS id,events.name AS event,categories.name AS categories
FROM events,categories,event_dates,event_categories
WHERE events.preview = 0 AND event_dates.start_date > DATE(NOW())
AND events.id = event_dates.event_id AND events.id = event_categories.event_id AND event_categories.category_id = categories.id
GROUP BY events.id LIMIT 0,5
結果如下(event_categories是鏈接事件類別表) :
Array ([id] => 144 [event] => Twickenham Stadium Tours and World Rugby Museum [name] => Sport)
但是,這是一個多對多的關係,這個查詢只返回一個類別。如何將這種重新排列/編制一個查詢,會抓住所有類別