Mysql
 sql >> Base de données >  >> RDS >> Mysql

Filtre MySQL sur plusieurs à plusieurs

Essayez ceci

SELECT r.id, r.name, GROUP_CONCAT(DISTINCT(i.name)) as items
 FROM receipts r
 LEFT JOIN receipts-ingredients ri ON(ri.receipt_id = r.id)
 LEFT JOIN ingredients i ON(ri.ingredient_id = i.id)
 GROUP BY r.id
 HAVING FIND_IN_SET('tomato',items) AND FIND_IN_SET('pesto',items)