mysql n:m relationship: Find rows with several specific relations

后端 未结 2 1234
生来不讨喜
生来不讨喜 2021-01-27 17:27

I have two SQL Tables, \'products\' and \'tags\'. They have an n:m relationship, using a third table \'product_tags\'.

I want to use a query to find every product that h

2条回答
  •  伪装坚强ぢ
    2021-01-27 17:57

    Try this

    SELECT * FROM

     PRODUCTS p 
     JOIN PRODUCT_TAGS pt ON p.ID = pt.PRODUCT_ID
     JOIN TAGS t ON pt.TAG_ID = t.ID AND
          t.ID IN (1, 23, 54)
    

    I am assuming the column names. I think the column names are straight forward and you can use your column names easily. if you need more clarification let me know.

提交回复
热议问题