Selecting against subsets of a list in MySQL

前端 未结 7 1959
谎友^
谎友^ 2021-01-12 07:21

I\'m quite a begginer and I have two tables: \"product\" and \"product attributes\".

Here\'s some imaginary data (the actual stuff involves more tables )

Pr

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 07:56

    let me post simple imaginary data ( the actual stuff involves more tables )

    table products

    product_id | product_name                  
    10          |   aaa                           
    11     |    bbb  
    

    table product_attribute

    attribute_id | product_id  
    21 | 10 23 | 10 24 | 10 21 | 11 24 | 11

    i want that:

    • when I filter for (21,24) to be returned only product 11 (bbb)
    • when I filter for (21,23,24) to be returned both products
    • when I filter for (21) only to be returned none ( because no product has only that attribute )

提交回复
热议问题