Devi create tot self join.
Per esempio per trovare tutti i prodotti che hanno gli ingredienti 1,2 e 3 la query diventerebbe
codice:
select tab1.prodotto from tab1
inner join tab3 as due on tab1.id = due.prodid
inner join tab3 as tre on due.prodid = tre.prodid
inner join tab3 as quattro on due.prodid = quattro.prodid
where due.ingid = 1 and tre.ingid = 2 and quattro.ingid = 3
oppure ho pensato a un'altra soluzione tramite la concatenazione degli id degli ingredienti e relativa ricerca all'interno di tale stringa
codice:
select tab1.prodotto,group_concat(tab3.ingid) as prodotti
from tab1
inner join tab3 on tab1.id = tab3.prodid
group by prodid
having find_in_set(1,prodotti) and find_in_set(2,prodotti) and find_in_set(3,prodotti)