{"id":6441,"date":"2024-11-14T08:54:25","date_gmt":"2024-11-14T00:54:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6441\/"},"modified":"2024-11-14T08:54:25","modified_gmt":"2024-11-14T00:54:25","slug":"mysql-full-join%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6441\/","title":{"rendered":"mysql full join\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  full join \u662f\u8fde\u63a5\u64cd\u4f5c\u7b26\uff0c\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u5305\u62ec\u4e0d\u5339\u914d\u884c\uff0c\u4e0d\u5339\u914d\u884c\u4f7f\u7528 null \u586b\u5145\u7f3a\u5931\u503c\u3002\u4f7f\u7528\u573a\u666f\uff1a\u68c0\u7d22\u4e24\u8868\u6240\u6709\u884c\uff0c\u7ef4\u62a4\u8868\u5173\u7cfb\uff0c\u67e5\u627e\u4e0d\u5339\u914d\u884c\u3002\u8bed\u6cd5\uff1aselect * from table1 full join table2 on table1.column = table2.column\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/02\/2024080220312276092.jpg\" class=\"aligncenter\" title=\"mysql full join\u7528\u6cd5\u63d2\u56fe\" alt=\"mysql full join\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL FULL JOIN \u7528\u6cd5<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a\u4ec0\u4e48\u662f FULL JOIN\uff1f<\/strong><\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong> FULL JOIN \u662f\u4e00\u79cd\u8fde\u63a5\u64cd\u4f5c\u7b26\uff0c\u5b83\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5339\u914d\u7684\u884c\u4ee5\u53ca\u4e0d\u5339\u914d\u7684\u884c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u8fd4\u56de\u7b1b\u5361\u5c14\u79ef\uff0c\u5e76\u7528 NULL \u503c\u586b\u5145\u7f3a\u5931\u7684\u884c\u3002<\/p>\n<p><strong>\u7528\u6cd5\uff1a<\/strong><\/p>\n<p>\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT *\nFROM table1\nFULL JOIN table2\nON table1.column = table2.column;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7279\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u884c\uff0c\u5305\u62ec\u4e0d\u5339\u914d\u7684\u884c\u3002<\/li>\n<li>\u5bf9\u4e8e\u4e0d\u5339\u914d\u7684\u884c\uff0c\u7f3a\u5931\u7684\u5217\u503c\u5c06\u88ab\u586b\u5145\u4e3a NULL\u3002<\/li>\n<li>FULL JOIN \u662f\u6700\u5168\u9762\u7684\u8fde\u63a5\u7c7b\u578b\uff0c\u56e0\u4e3a\u5b83\u4fdd\u8bc1\u8fd4\u56de\u6240\u6709\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u4f55\u65f6\u4f7f\u7528\uff1a<\/strong><\/p>\n<p>FULL JOIN \u901a\u5e38\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\u5f53\u9700\u8981\u68c0\u7d22\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u884c\u65f6\uff0c\u5373\u4f7f\u5b58\u5728\u4e0d\u5339\u914d\u3002<\/li>\n<li>\u5f53\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u7ef4\u62a4\u8868\u4e4b\u95f4\u7684\u5173\u7cfb\u65f6\uff0c\u5373\u4f7f\u8fd9\u4e9b\u5173\u7cfb\u5e76\u4e0d\u603b\u662f\u663e\u5f0f\u5b9a\u4e49\u3002<\/li>\n<li>\u5f53\u9700\u8981\u67e5\u627e\u4e0d\u5339\u914d\u7684\u884c\u65f6\uff0c\u4f8b\u5982\u67e5\u627e\u5728\u53e6\u4e00\u4e2a\u8868\u4e2d\u6ca1\u6709\u8bb0\u5f55\u7684\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u8868\uff1a<\/p>\n<pre>table1:\n+----+--------+\n| id | name    |\n+----+--------+\n| 1  | John    |\n| 2  | Mary    |\n| 3  | Bob     |\n+----+--------+\n\ntable2:\n+----+--------+\n| id | address |\n+----+--------+\n| 1  | 123 Main St |\n| 2  | 456 Elm St  |\n| 4  | 789 Oak St  |\n+----+--------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6267\u884c\u4ee5\u4e0b FULL JOIN \u67e5\u8be2\uff1a<\/p>\n<pre>SELECT *\nFROM table1\nFULL JOIN table2\nON table1.id = table2.id;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>+----+--------+----+--------+\n| id | name    | id | address |\n+----+--------+----+--------+\n| 1  | John    | 1  | 123 Main St |\n| 2  | Mary    | 2  | 456 Elm St  |\n| 3  | Bob     | NULL | NULL      |\n| NULL | NULL      | 4  | 789 Oak St  |\n+----+--------+----+--------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ed3\u679c\u96c6\u5305\u542b\u4e24\u4e2a\u8868\u7684\u6240\u6709\u884c\uff0c\u5305\u62ec\u4e0d\u5339\u914d\u884c\uff08id=3 \u548c id=4\uff09\u3002\u5bf9\u4e8e\u4e0d\u5339\u914d\u7684\u884c\uff0caddress \u5217\u586b\u5145\u4e3a NULL\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f full join\u7528\u6cd5\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>full join \u662f\u8fde\u63a5\u64cd\u4f5c\u7b26\uff0c\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u5305\u62ec\u4e0d\u5339\u914d\u884c\uff0c\u4e0d\u5339\u914d\u884c\u4f7f\u7528 null \u586b\u5145\u7f3a\u5931\u503c\u3002\u4f7f\u7528\u573a\u666f\uff1a\u68c0\u7d22\u4e24\u8868\u6240\u6709\u884c\uff0c\u7ef4\u62a4\u8868\u5173\u7cfb\uff0c\u67e5\u627e\u4e0d\u5339\u914d\u884c\u3002\u8bed\u6cd5\uff1aselect * from table1 full join table2 on table1.column = table2.column\u3002 MySQL FULL JOIN \u7528\u6cd5 \u95ee\u9898\uff1a\u4ec0\u4e48\u662f FULL JOIN\uff1f \u56de\u7b54\uff1a FULL JOIN \u662f\u4e00\u79cd\u8fde\u63a5\u64cd\u4f5c\u7b26\uff0c\u5b83\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5339\u914d\u7684\u884c\u4ee5\u53ca\u4e0d\u5339\u914d\u7684\u884c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u8fd4\u56de\u7b1b\u5361\u5c14\u79ef\uff0c\u5e76\u7528 NULL \u503c\u586b\u5145\u7f3a\u5931\u7684\u884c\u3002 \u7528\u6cd5\uff1a \u8bed\u6cd5\u5982\u4e0b\uff1a SELECT * FROM table1 FULL JOIN table2 ON table1.column = table2.column; \u767b\u5f55\u540e\u590d\u5236 \u7279\u70b9\uff1a \u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u884c\uff0c\u5305\u62ec\u4e0d\u5339\u914d\u7684\u884c\u3002 \u5bf9\u4e8e\u4e0d\u5339\u914d\u7684\u884c\uff0c\u7f3a\u5931\u7684\u5217\u503c\u5c06\u88ab\u586b\u5145\u4e3a NULL\u3002 FULL JOIN \u662f\u6700\u5168\u9762\u7684\u8fde\u63a5\u7c7b\u578b\uff0c\u56e0\u4e3a\u5b83\u4fdd\u8bc1\u8fd4\u56de\u6240\u6709\u884c\u3002 \u4f55\u65f6\u4f7f\u7528\uff1a FULL JOIN \u901a\u5e38\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\uff1a \u5f53\u9700\u8981\u68c0\u7d22\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u884c\u65f6\uff0c\u5373\u4f7f\u5b58\u5728\u4e0d\u5339\u914d\u3002 \u5f53\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u7ef4\u62a4\u8868\u4e4b\u95f4\u7684\u5173\u7cfb\u65f6\uff0c\u5373\u4f7f\u8fd9\u4e9b\u5173\u7cfb\u5e76\u4e0d\u603b\u662f\u663e\u5f0f\u5b9a\u4e49\u3002 [&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-6441","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6441","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=6441"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6441\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}