Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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
如何在mysql中进行外部连接_Mysql - Fatal编程技术网

如何在mysql中进行外部连接

如何在mysql中进行外部连接,mysql,Mysql,我有两张桌子 table_brands - brand_id, brand_name table_products - product_id, product_name, brand_id 有了这个疑问 SELECT B.*, COUNT(P.product_id) from table_brands B INNER JOIN table_products P WHERE B.brand_id = P.brand_id GROUP BY(P.brand_id) 我正在根据该品牌id获

我有两张桌子

table_brands - brand_id, brand_name
table_products - product_id, product_name, brand_id
有了这个疑问

SELECT B.*, COUNT(P.product_id) 
from table_brands B 
INNER JOIN table_products P 
WHERE B.brand_id = P.brand_id 
GROUP BY(P.brand_id)
我正在根据该品牌id获取品牌详细信息和产品数量。但我没有获取那些没有产品的品牌的品牌详细信息

如果没有适用于该品牌的产品,我希望获得所有品牌和产品数量(产品数量为0)


有人能帮我吗。

使用
左连接,如下所示:

SELECT B.*, COUNT(P.product_id) 
from table_brands B 
LEFT JOIN table_products P ON B.brand_id = P.brand_id 
GROUP BY B.brand_id

问题标题中有“outer”,但没有“left”?古怪的这可能在将来有所帮助