{"id":6810,"date":"2024-11-14T12:29:45","date_gmt":"2024-11-14T04:29:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6810\/"},"modified":"2024-11-14T12:29:45","modified_gmt":"2024-11-14T04:29:45","slug":"mysql-join-%e6%9f%a5%e8%af%a2%e4%b8%ad%e4%b8%b4%e6%97%b6%e8%a1%a8%e4%bc%9a%e5%8c%85%e5%90%ab%e5%93%aa%e4%ba%9b%e5%ad%97%e6%ae%b5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6810\/","title":{"rendered":"MySQL JOIN \u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u4f1a\u5305\u542b\u54ea\u4e9b\u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172994223589345.jpg\" class=\"aligncenter\" title=\"MySQL JOIN \u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u4f1a\u5305\u542b\u54ea\u4e9b\u5b57\u6bb5\uff1f\u63d2\u56fe\" alt=\"MySQL JOIN \u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u4f1a\u5305\u542b\u54ea\u4e9b\u5b57\u6bb5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> join\u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u5b57\u6bb5\u8003\u5bdf<\/strong><\/p>\n<p>\u5f53mysql\u6267\u884cjoin\u67e5\u8be2\u65f6\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u8868\u6765\u5b58\u50a8\u67e5\u8be2\u7ed3\u679c\u3002\u901a\u5e38\uff0c\u4e34\u65f6\u8868\u5305\u542b join \u4e2d\u6240\u6709\u8868\u7684\u5b57\u6bb5\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e34\u65f6\u8868\u53ef\u80fd\u4f1a\u5305\u542b\u66f4\u5c11\u7684\u5b57\u6bb5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e join \u7684\u6761\u4ef6\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u8868 a \u548c\u8868 b\uff0c\u5b83\u4eec\u5206\u522b\u5305\u542b 4 \u4e2a\u5b57\u6bb5\uff1a<\/p>\n<p><strong>\u8868 a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b57\u6bb5\u540d<\/th>\n<th>\u6570\u636e\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>id<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>name<\/td>\n<td>varchar(255)<\/td>\n<\/tr>\n<tr>\n<td>status<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>delete_sign<\/td>\n<td>tinyint(1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u8868 b<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b57\u6bb5\u540d<\/th>\n<th>\u6570\u636e\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>id<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>a_id<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>status<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>delete_sign<\/td>\n<td>tinyint(1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u6267\u884c\u4ee5\u4e0b sql \u67e5\u8be2\uff1a<\/p>\n<pre>SELECT a.id, a.name, a.status, a.delete_sign \nFROM A a \nINNER JOIN B b ON a.id = b.a_id \nWHERE b.delete_sign = 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u751f\u6210\u7684\u4e34\u65f6\u8868\u5e94\u8be5\u662f<strong>n<\/strong>\uff0c\u53ea\u5305\u542b\u8868 a \u7684\u5fc5\u8981\u5b57\u6bb5\u548c\u8868 b \u4e2d\u7684 <strong>delete_sign<\/strong> \u5b57\u6bb5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><strong>\u4e34\u65f6\u8868 n<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b57\u6bb5\u540d<\/th>\n<th>\u6570\u636e\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>a.id<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>a.name<\/td>\n<td>varchar(255)<\/td>\n<\/tr>\n<tr>\n<td>a.status<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>a.delete_sign<\/td>\n<td>tinyint(1)<\/td>\n<\/tr>\n<tr>\n<td>b.delete_sign<\/td>\n<td>tinyint(1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u901a\u8fc7\u4f7f\u7528\u8f83\u5c11\u5b57\u6bb5\u7684\u4e34\u65f6\u8868\uff0cmysql \u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\uff0c\u56e0\u4e3a\u5b58\u50a8\u548c\u5904\u7406\u7684\u6570\u636e\u91cf\u66f4\u5c0f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL JOIN \u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u4f1a\u5305\u542b\u54ea\u4e9b\u5b57\u6bb5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>join\u67e5\u8be2\u4e2d\u4e34\u65f6\u8868\u5b57\u6bb5\u8003\u5bdf \u5f53mysql\u6267\u884cjoin\u67e5\u8be2\u65f6\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u8868\u6765\u5b58\u50a8\u67e5\u8be2\u7ed3\u679c\u3002\u901a\u5e38\uff0c\u4e34\u65f6\u8868\u5305\u542b join \u4e2d\u6240\u6709\u8868\u7684\u5b57\u6bb5\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e34\u65f6\u8868\u53ef\u80fd\u4f1a\u5305\u542b\u66f4\u5c11\u7684\u5b57\u6bb5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e join \u7684\u6761\u4ef6\u3002 \u5047\u8bbe\u6211\u4eec\u6709\u8868 a \u548c\u8868 b\uff0c\u5b83\u4eec\u5206\u522b\u5305\u542b 4 \u4e2a\u5b57\u6bb5\uff1a \u8868 a \u5b57\u6bb5\u540d \u6570\u636e\u7c7b\u578b id int name varchar(255) status int delete_sign tinyint(1) \u8868 b \u5b57\u6bb5\u540d \u6570\u636e\u7c7b\u578b id int a_id int status int delete_sign tinyint(1) \u6211\u4eec\u6267\u884c\u4ee5\u4e0b sql \u67e5\u8be2\uff1a SELECT a.id, a.name, a.status, a.delete_sign FROM A a INNER JOIN B b ON a.id = b.a_id [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6810","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6810"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6810\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}