sql - Mysql many to many query -


Going around this query is a mental block.

I have the following applause:

review_list : There are a lot of data in this, but in this case review_id is only an important thing, the record ID which I Currently interested in (int) variant_list : model (varchar), enabled (bool)
variant_review : model (varchar), id (int)

There are several tables linking the variant_review review_ id to the Variant_list in the review (in the model) of the model (s) and in it (for example):

  .. test1,22 test2,22 Test4,22 test1,23 te St2, 23 ... etc  

variant_list is a list of all possible models and whether they are enabled and (such):

  test1, correct exam 2, the correct test 3, the truth test 4, the truth  

what I am in mysql, this is a query, when a review_id returned (i.e., 22) returning a result area that returns each value Variant_review.model and whether it exists in the given review_id such as:

  test1,1 test2,1 test3,0 test4,1  

or Similar, which I can farm for some The webpage with the list of checkboxes for the character will make it available to all the models and exists in each table

< P> A little more about the name of the column:

  Choose variant_list.model, when the variant_review.model is not faucet, then join 1 different 0 end from HasReview to variant_list variant_review Variant_review at variant_review. Variant_review.model = variant_list.model and variant_review .review_id = 22  

Just for completeness, if that's the case that you have the same model and review_id with variant_review If there are multiple rows in the table, you need to do it differently:

  select variant_list.model, when the case exists (select Variant_review from VR as VR VR where VR .model = variant_list.model and VR.review_id = 22) then 1 other 0 Variant_li end cents  

Comments