Answer the question
In order to leave comments, you need to log in
How to implement many to many search through link table in YII in standard search method?
Question in continuation of the existing one: MySQL - select from a many-to-many table
There is a table with the names of stores `mags`:
`mag_id`, `mag_name`
a table with goods that are sold there `tovs`:
`tov_id`, `tov_name`
and a linking table `mag_tov`:
`mt_mag_id`, `mt_tov_id`
Suppose there are products 'milk', 'sausage', 'meat', 'cheese', 'vodka', 'tea', 'coffee', 'salt'. Each store sells several different products at the same time.
SELECT mags.*, COUNT(*) AS c FROM mag_tov, tovs, mags WHERE mt_tov_id = tov_id AND mt_mag_id = mag_id AND tov_name IN ('milk', 'meat' and 'tea') GROUP BY mag_id HAVING c = 3
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question