{"id":196193,"date":"2024-11-13T21:15:22","date_gmt":"2024-11-13T13:15:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/196193\/"},"modified":"2024-11-13T21:15:23","modified_gmt":"2024-11-13T13:15:23","slug":"%e6%8e%8c%e6%8f%a1%e6%95%b8%e6%93%9a%e5%ba%abjoin%e5%87%bd%e6%95%b8%e7%9a%84%e5%af%a6%e7%8f%be%e6%96%b9%e6%b3%95-%e6%95%b8%e6%93%9a%e5%ba%abjoin%e5%87%bd%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/196193\/","title":{"rendered":"\u638c\u63e1\u6578\u64da\u5eabjoin\u51fd\u6578\u7684\u5be6\u73fe\u65b9\u6cd5 (\u6578\u64da\u5eabjoin\u51fd\u6578)"},"content":{"rendered":"<h1 id=\"%e6%8e%8c%e6%8f%a1%e6%95%b8%e6%93%9a%e5%ba%abjoin%e5%87%bd%e6%95%b8%e7%9a%84%e5%af%a6%e7%8f%be%e6%96%b9%e6%b3%95-sMEKeoZVbq\">\u638c\u63e1\u6578\u64da\u5eabJOIN\u51fd\u6578\u7684\u5be6\u73fe\u65b9\u6cd5<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cJOIN\u51fd\u6578\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\uff0c\u5b83\u5141\u8a31\u7528\u6236\u5f9e\u591a\u500b\u8868\u4e2d\u6aa2\u7d22\u6578\u64da\u3002\u9019\u5c0d\u65bc\u9700\u8981\u95dc\u806f\u4e0d\u540c\u6578\u64da\u96c6\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eJOIN\u51fd\u6578\u7684\u4e0d\u540c\u985e\u578b\u53ca\u5176\u5be6\u73fe\u65b9\u6cd5\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u4f7f\u7528JOIN\u3002<\/p>\n<h2 id=\"join%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-sMEKeoZVbq\">JOIN\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>JOIN\u662f\u4e00\u7a2eSQL\u64cd\u4f5c\uff0c\u7528\u65bc\u5c07\u4f86\u81ea\u5169\u500b\u6216\u591a\u500b\u8868\u7684\u884c\u6839\u64da\u76f8\u95dc\u5217\u9032\u884c\u7d44\u5408\u3002\u9019\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u5728\u4e00\u500b\u67e5\u8a62\u4e2d\u7372\u53d6\u4f86\u81ea\u4e0d\u540c\u8868\u7684\u6578\u64da\u3002JOIN\u7684\u4e3b\u8981\u985e\u578b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong id=\"inner-join-sMEKeoZVbq\">INNER JOIN<\/strong><\/li>\n<li><strong id=\"left-join-sMEKeoZVbq\">LEFT JOIN<\/strong><\/li>\n<li><strong id=\"right-join-sMEKeoZVbq\">RIGHT JOIN<\/strong><\/li>\n<li><strong id=\"full-outer-join-sMEKeoZVbq\">FULL OUTER JOIN<\/strong><\/li>\n<\/ul>\n<h2 id=\"inner-join-sMEKeoZVbq\">INNER JOIN<\/h2>\n<p>INNER JOIN\u662f\u6700\u5e38\u7528\u7684JOIN\u985e\u578b\uff0c\u5b83\u8fd4\u56de\u5169\u500b\u8868\u4e2d\u5339\u914d\u7684\u884c\u3002\u7576\u5169\u500b\u8868\u4e2d\u6709\u76f8\u540c\u7684\u503c\u6642\uff0c\u9019\u4e9b\u884c\u5c07\u88ab\u9078\u4e2d\u3002<\/p>\n<pre><code>SELECT a.column1, b.column2\nFROM table1 a\nINNER JOIN table2 b ON a.common_column = b.common_column;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u53ea\u6709\u7576table1\u548ctable2\u4e2d\u7684common_column\u76f8\u7b49\u6642\uff0c\u624d\u6703\u8fd4\u56de\u76f8\u61c9\u7684\u884c\u3002<\/p>\n<h2 id=\"left-join-sMEKeoZVbq\">LEFT JOIN<\/h2>\n<p>LEFT JOIN\u8fd4\u56de\u5de6\u5074\u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u5373\u4f7f\u53f3\u5074\u8868\u4e2d\u6c92\u6709\u5339\u914d\u7684\u884c\u3002\u5982\u679c\u53f3\u5074\u8868\u4e2d\u6c92\u6709\u5339\u914d\u7684\u884c\uff0c\u5247\u7d50\u679c\u4e2d\u5c07\u986f\u793aNULL\u3002<\/p>\n<pre><code>SELECT a.column1, b.column2\nFROM table1 a\nLEFT JOIN table2 b ON a.common_column = b.common_column;<\/code><\/pre>\n<p>\u9019\u610f\u5473\u8457\u5373\u4f7ftable2\u4e2d\u6c92\u6709\u8207table1\u5339\u914d\u7684\u884c\uff0ctable1\u4e2d\u7684\u6240\u6709\u884c\u4ecd\u7136\u6703\u88ab\u8fd4\u56de\u3002<\/p>\n<h2 id=\"right-join-sMEKeoZVbq\">RIGHT JOIN<\/h2>\n<p>RIGHT JOIN\u8207LEFT JOIN\u76f8\u53cd\uff0c\u5b83\u8fd4\u56de\u53f3\u5074\u8868\u4e2d\u7684\u6240\u6709\u884c\u3002\u5982\u679c\u5de6\u5074\u8868\u4e2d\u6c92\u6709\u5339\u914d\u7684\u884c\uff0c\u5247\u7d50\u679c\u4e2d\u5c07\u986f\u793aNULL\u3002<\/p>\n<pre><code>SELECT a.column1, b.column2\nFROM table1 a\nRIGHT JOIN table2 b ON a.common_column = b.common_column;<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u5373\u4f7ftable1\u4e2d\u6c92\u6709\u8207table2\u5339\u914d\u7684\u884c\uff0ctable2\u4e2d\u7684\u6240\u6709\u884c\u4ecd\u7136\u6703\u88ab\u8fd4\u56de\u3002<\/p>\n<h2 id=\"full-outer-join-sMEKeoZVbq\">FULL OUTER JOIN<\/h2>\n<p>FULL OUTER JOIN\u8fd4\u56de\u5169\u500b\u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u7121\u8ad6\u662f\u5426\u6709\u5339\u914d\u7684\u884c\u3002\u5982\u679c\u67d0\u4e00\u5074\u6c92\u6709\u5339\u914d\u7684\u884c\uff0c\u5247\u7d50\u679c\u4e2d\u5c07\u986f\u793aNULL\u3002<\/p>\n<pre><code>SELECT a.column1, b.column2\nFROM table1 a\nFULL OUTER JOIN table2 b ON a.common_column = b.common_column;<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u7372\u5f97\u5169\u500b\u8868\u4e2d\u6240\u6709\u7684\u6578\u64da\uff0c\u7121\u8ad6\u5b83\u5011\u662f\u5426\u6709\u95dc\u806f\u3002<\/p>\n<h2 id=\"join%e7%9a%84%e4%bd%bf%e7%94%a8%e5%a0%b4%e6%99%af-sMEKeoZVbq\">JOIN\u7684\u4f7f\u7528\u5834\u666f<\/h2>\n<p>JOIN\u51fd\u6578\u5728\u8a31\u591a\u5834\u666f\u4e2d\u90fd\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u5f9e\u5ba2\u6236\u8868\u548c\u8a02\u55ae\u8868\u4e2d\u7372\u53d6\u5ba2\u6236\u7684\u8a02\u55ae\u4fe1\u606f\u3002<\/li>\n<li>\u5f9e\u7522\u54c1\u8868\u548c\u985e\u5225\u8868\u4e2d\u7372\u53d6\u7522\u54c1\u7684\u985e\u5225\u4fe1\u606f\u3002<\/li>\n<li>\u5f9e\u54e1\u5de5\u8868\u548c\u90e8\u9580\u8868\u4e2d\u7372\u53d6\u54e1\u5de5\u7684\u90e8\u9580\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-sMEKeoZVbq\">\u7e3d\u7d50<\/h2>\n<p>\u638c\u63e1JOIN\u51fd\u6578\u7684\u4f7f\u7528\u5c0d\u65bc\u6578\u64da\u5eab\u7ba1\u7406\u548c\u67e5\u8a62\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u7406\u89e3INNER JOIN\u3001LEFT JOIN\u3001RIGHT JOIN\u548cFULL OUTER JOIN\u7684\u4e0d\u540c\u7279\u6027\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5f9e\u591a\u500b\u8868\u4e2d\u6aa2\u7d22\u6240\u9700\u7684\u6578\u64da\u3002\u7121\u8ad6\u662f\u5728\u958b\u767c\u61c9\u7528\u7a0b\u5e8f\u9084\u662f\u9032\u884c\u6578\u64da\u5206\u6790\u6642\uff0cJOIN\u90fd\u662f\u4e00\u500b\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\u3002\u7121\u8ad6\u662f\u642d\u5efa\u7db2\u7ad9\u9084\u662f\u9032\u884c\u6578\u64da\u5206\u6790\uff0c<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u6578\u64da\u5eabjoin\u51fd\u6578\u7684\u5be6\u73fe\u65b9\u6cd5\uff0c\u638c\u63e1\u4e0d\u540c\u985e\u578b\u7684join\u64cd\u4f5c\uff0c\u63d0\u5347\u6578\u64da\u67e5\u8a62\u6548\u7387\u8207\u9748\u6d3b\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-196193","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/196193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=196193"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/196193\/revisions"}],"predecessor-version":[{"id":196194,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/196193\/revisions\/196194"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=196193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=196193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=196193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}