Selecting against subsets of a list in MySQL

前端 未结 7 1886
谎友^
谎友^ 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  <br>
    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 )
    0 讨论(0)
提交回复
热议问题