Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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_Join - Fatal编程技术网

Mysql 为什么不是';这不管用吗?

Mysql 为什么不是';这不管用吗?,mysql,join,Mysql,Join,数据库表 ss_商人 +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | pk_merchant_id

数据库表

ss_商人

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| pk_merchant_id | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name           | varchar(45)  | YES  |     | NULL    |                |
| website        | varchar(100) | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+
商铺

+----------------------+-------------+------+-----+---------+----------------+
| Field                | Type        | Null | Key | Default | Extra          |
+----------------------+-------------+------+-----+---------+----------------+
| pk_merchant_store_id | bigint(20)  | NO   | PRI | NULL    | auto_increment |
| fk_pk_merchant_id    | bigint(20)  | YES  |     | NULL    |                |
| street               | varchar(20) | YES  |     | NULL    |                |
| city                 | varchar(20) | YES  |     | NULL    |                |
| postcode             | varchar(8)  | YES  |     | NULL    |                |
| telephone            | varchar(15) | YES  |     | NULL    |                |
| email                | varchar(45) | YES  |     | NULL    |                |
+----------------------+-------------+------+-----+---------+----------------+
ss_商户_商店_评级

+-----------------------------+------------+------+-----+---------+----------------+
| Field                       | Type       | Null | Key | Default | Extra          |
+-----------------------------+------------+------+-----+---------+----------------+
| pk_merchant_store_rating_id | bigint(20) | NO   | PRI | NULL    | auto_increment |
| fk_pk_merchant_store_id     | bigint(20) | NO   |     | NULL    |                |
| rating                      | int(1)     | YES  |     | NULL    |                |
+-----------------------------+------------+------+-----+---------+----------------+
我的问题是:

SELECT *  
FROM ss_merchant 
JOIN ss_merchant_stores 
ON ss_merchant.pk_merchant_id = ss_merchant_stores.fk_pk_merchant_id 
JOIN ss_merchant_store_rating 
ON ss_merchant_stores.pk_merchant_store_id = ss_merchant_store_rating.fk_pk_merchant_store_id

您的联接没有什么特别的错误,但它确实假设所有三个表的每个
merchant\u id
至少有一行。如果您想允许不存在的商品,则使用“

”来考虑行。 如果没有匹配的行,则 中的右表打开或使用中的零件 左连接,包含所有列的行 设置为NULL用于右侧 桌子你可以利用这个事实来发现 表中没有 另一个表中的对应项:

此示例查找中的所有行 左\u tbl的id值不是 以右键显示(即全部 左侧的行中没有对应的 右侧的行(待定)。这是假设 right_tbl.id被声明为非空


你的桌子叫ss_merchant_stores还是ss_merchant_stores?你说“不工作”是什么意思?您是否收到错误消息?
SELECT left_tbl.*   FROM left_tbl LEFT JOIN right_tbl 
ON left_tbl.id = right_tbl.id   WHERE right_tbl.id IS NULL;