Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有ID列表的Mysql多连接查询_Mysql_Sql_Join - Fatal编程技术网

具有ID列表的Mysql多连接查询

具有ID列表的Mysql多连接查询,mysql,sql,join,Mysql,Sql,Join,我有三张桌子 商品到商店 产品类别 产品描述 如何获取类别ID列表68,40,41,55,66中的产品ID列表。。。以及制造商ID列表210788233。。。。并将_id=1存储在一个SQL查询中,以避免使用php进行foreach循环,并避免重复的产品id?当您将。。。在类别/制造商列表之后,您指的是所有类别id或仅列出的类别id。我指的是列出的类别id SELECT DISTINCT p.product_id FROM products_to_stores p INNER JOIN prod

我有三张桌子

商品到商店

产品类别

产品描述


如何获取类别ID列表68,40,41,55,66中的产品ID列表。。。以及制造商ID列表210788233。。。。并将_id=1存储在一个SQL查询中,以避免使用php进行foreach循环,并避免重复的产品id?

当您将。。。在类别/制造商列表之后,您指的是所有类别id或仅列出的类别id。我指的是列出的类别id
SELECT DISTINCT p.product_id FROM products_to_stores p INNER JOIN products_to_categories c ON c.product_id = p.product_id INNER JOIN product_descriptions d ON d.product_id = p.product_id 
WHERE 
manufacturer_id IN (210,788) AND category_id IN (40,44) AND store_id = 1
product_id | category_id
____________________
50         | 69
50         | 68
50         | 40
51         | 66
52         | 55
69         | 41
111        | 40
111        | 70
product_id | manufacturer_id (parent category id)
____________________
68         | 345
69         | 233
70         | 788
50         | 788
111        | 788
51         | 210
52         | 788
SELECT DISTINCT p.product_id FROM products_to_stores p INNER JOIN products_to_categories c ON c.product_id = p.product_id INNER JOIN product_descriptions d ON d.product_id = p.product_id 
WHERE 
manufacturer_id IN (210,788) AND category_id IN (40,44) AND store_id = 1
SELECT descriptions.product_id FROM product_descriptions AS descriptions
    INNER JOIN products_to_categories AS category ON category.product_id = descriptions.product_id AND category.category_id IN (/* Your categories */)
    INNER JOIN products_to_stores AS stores ON stores.product_id = descriptions.product_id AND stores.store_id = 1
WHERE descriptions.manufacturer_id IN (/* .... */)
GROUP BY descriptions.product_id