{"id":713,"date":"2021-07-27T16:06:01","date_gmt":"2021-07-27T08:06:01","guid":{"rendered":"https:\/\/fireinsect.top\/?p=713"},"modified":"2021-07-29T18:51:12","modified_gmt":"2021-07-29T10:51:12","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e5%9f%ba%e7%a1%80%e2%85%a3%ef%bc%88%e5%85%b3%e8%81%94%e6%9f%a5%e8%af%a2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2021\/07\/27\/%e6%95%b0%e6%8d%ae%e5%ba%93%e5%9f%ba%e7%a1%80%e2%85%a3%ef%bc%88%e5%85%b3%e8%81%94%e6%9f%a5%e8%af%a2%ef%bc%89\/","title":{"rendered":"\u6570\u636e\u5e93\u57fa\u7840\u2163\uff08\u5173\u8054\u67e5\u8be2\uff09"},"content":{"rendered":"\n<p>\u5f53\u6211\u4eec\u67e5\u8be2\u5982\u8bfe\u7a0b\u4fe1\u606f\u7684\u65f6\u5019\u5f80\u5f80\u9700\u8981\u8fde\u540c\u8bfe\u7a0b\u7684\u5b66\u4e1a\u5bfc\u5e08\u4e00\u540c\u67e5\u8be2\u51fa\u6765\uff0c\u6700\u539f\u59cb\u7684\u65b9\u6cd5\u81ea\u7136\u662f\u5c06\u5b66\u4e1a\u5bfc\u5e08\u7684\u4fe1\u606f\u5355\u72ec\u6dfb\u52a0\u5728\u8bfe\u7a0b\u6570\u636e\u5185\uff0c\u4f46\u5728\u6570\u636e\u590d\u7528\u7387\u9ad8\u7684\u60c5\u51b5\u4e0b\u663e\u7136\u9700\u8981\u5c06\u5bfc\u5e08\u4fe1\u606f\u5355\u72ec\u653e\u7f6e\u5728\u4e00\u5f20\u8868\u4e2d\uff0c\u8fd9\u662f\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u884c\u591a\u8868\u6570\u636e\u67e5\u8be2\u5c31\u662f\u5173\u8054\u67e5\u8be2\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u5de6\u8fde\u63a5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  TableA <strong>LEFT<\/strong>  <strong>JOIN<\/strong>\n  TableB\n  <strong>ON<\/strong> <strong>condition<\/strong>;<\/code><\/pre>\n\n\n\n<ul class=\"list1 wp-block-list\"><li>JOIN \u662f\u5173\u8054\u67e5\u8be2\u7684\u5173\u952e\u8bcd\uff0c\u57fa\u7840\u7684\u7ed3\u6784\u662f TableA JOIN TableB\uff0c\u5373\u8868 A \u548c\u8868 B \u5173\u8054\u67e5\u8be2\u3002<\/li><li>LEFT \u8868\u793a\u662f\u5de6\u8fde\u63a5<\/li><li>ON \u662f\u5173\u8054\u67e5\u8be2\u7684\u6761\u4ef6\u3002<\/li><li>\u5de6\u8fde\u63a5\u5c31\u662f\u8fd4\u56de\u5de6\u8868\u7684\u6240\u6709\u6570\u636e\uff0c\u5373\u4f7f\u53f3\u8868\u6ca1\u6709\u5339\u914d\u7684\u6570\u636e\uff08\u6b64\u65f6\u53f3\u8868\u4f1a\u4ee5 NULL \u7684\u5f62\u5f0f\u5339\u914d\u6570\u636e\uff09\u3002<\/li><\/ul>\n\n\n\n<p>\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  ykd_teacher\n  <strong>LEFT<\/strong> <strong>JOIN<\/strong> ykd_course <strong>ON<\/strong> ykd_teacher.id = ykd_course.teacher_id;<\/code><\/pre>\n\n\n\n<ul class=\"list1 wp-block-list\"><li>ykd_teacher \u662f\u8868 A\uff0cykd_course \u662f\u8868 B<\/li><li>ykd_teacher.id \u662f\u6307\u8fd9\u5f20\u8868\u7684 id \u5b57\u6bb5\uff0c\u540c\u7406 ykd_course.teacher_id \u662f\u6307\u8fd9\u5f20\u8868\u7684 teacher_id \u8fd9\u4e2a\u5b57\u6bb5<\/li><li>\u6211\u4eec\u7684\u67e5\u8be2\u6761\u4ef6\uff0c\u8ba9\u4e0a\u9762 2 \u4e2a\u5b57\u6bb5\u76f8\u7b49\u5e76\u5339\u914d<\/li><\/ul>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u53f3\u8fde\u63a5<\/p>\n\n\n\n<p>\u53f3\u8fde\u63a5\u4e0e\u5de6\u8fde\u63a5\u76f8\u4f3c\uff0c\u5373\u8fd4\u56de\u53f3\u8868\u6240\u6709\u7684\u6570\u636e\u5373\u4f7f\u5de6\u8868\u6ca1\u6709\u5339\u914d\u7684\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  TableA <strong>RIGHT<\/strong> <strong>JOIN<\/strong> \n  TableB \n  <strong>ON<\/strong> <strong>condition<\/strong>;<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u591a\u8868\u5173\u8054\u67e5\u8be2<\/p>\n\n\n\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u6709\u65f6\u5019\u4f1a\u5bf9\u4e09\u5f20\u8868\u4ee5\u4e0a\u8fdb\u884c\u5173\u8054\u67e5\u8be2\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5f80\u5f80\u4f1a\u9009\u4e2d\u4e00\u5f20\u8868\u4f5c\u4e3a\u4e3b\u8868\uff0c\u4ee5\u5b83\u4e3a\u57fa\u51c6\uff0c\u8fdb\u884c LEFT JOIN \u6216 RIGHT JOIN \u67e5\u8be2\u3002\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  TableA \n  <strong>LEFT<\/strong> <strong>JOIN<\/strong> TableB <strong>ON<\/strong> conditionA\n  <strong>LEFT<\/strong> <strong>JOIN<\/strong> TableC <strong>ON<\/strong> conditionB;<\/code><\/pre>\n\n\n\n<p>\u5373\u5728\u4e09\u8005\u4e2d\u627e\u5230\u4e2d\u95f4\u503c\u8fdb\u884c\u67e5\u8be2\u3002<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u5185\u8fde\u63a5<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u662f\u5927\u5b66\u67d0\u95e8\u8bfe\u7684\u8001\u5e08\uff0c\u6211\u4eec\u9700\u8981\u67e5\u8be2\u73ed\u7ea7A\u4e2d\u53c2\u4e0eB\u8003\u8bd5\u7684\u5b66\u751f\uff0c\uff08A\uff0cB\u540c\u65f6\u7b26\u5408\u67d0\u4e00\u4e2a\u6761\u4ef6\u7684\u6570\u636e\uff09\uff0c\u5f97\u5230\u7684\u6570\u636e\u662f\u5185\u90e8\u5171\u6709\u7684\u6570\u636e\uff0c\u6240\u4ee5\u8fde\u63a5\u65b9\u5f0f\u79f0\u4e3a\u5185\u8fde\u63a5\uff08INNER JOIN\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  Table_A\n  <strong>INNER<\/strong> <strong>JOIN<\/strong> Table_B\n<strong>ON<\/strong>\n  Table_A.id = Table_B.student_id;<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u5916\u8fde\u63a5\u62d3\u5c55<\/p>\n\n\n\n<p>\u4e4b\u524d\u6211\u5916\u8fde\u63a5\uff0c\u6211\u4eec\u6240\u67e5\u8be2\u7684\u662f\u5355\u72ecA\u6216\u8005B\u8868\u5185\u7684\u6570\u636e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/qgt-style.oss-cn-hangzhou.aliyuncs.com\/newcoursep4\/d1\/d1-5\/v2-e492481e964541f2764fa5b529790bae_1440w.jpg?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<p>\u4f46\u6211\u4eec\u6709\u65f6\u5019\u9700\u8981\u67e5\u8be2\u4e0d\u4e0eB\u6240\u5173\u8054\u7684A\u8868\u5185\u6570\u636e\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/qgt-style.oss-cn-hangzhou.aliyuncs.com\/newcoursep4\/d1\/d1-5\/v2-dd0093c24ed334d24de6498247d22e6a_1440w.jpg?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  Table_A\n  <strong>LEFT<\/strong> <strong>JOIN<\/strong> Table_B <strong>ON<\/strong> Table_A.id = Table_B.student_id\n<strong>WHERE<\/strong>\n  Table_B.student_id <strong>IS<\/strong> <strong>NULL<\/strong>;<\/code><\/pre>\n\n\n\n<p>\u5373\u67e5\u8be2\u5230\u4e0d\u5305\u542bB\u8868\u6240\u62e5\u6709\u7684 student_id<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">UNION\u5173\u952e\u8bcd<\/p>\n\n\n\n<p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u67e5\u8be2\u4e24\u5f20\u8868\u91cc\u6240\u6709\u7684\u6570\u636e\uff0c\u8fd9\u65f6\u6211\u4eec\u5c31\u9700\u8981 union \u5173\u952e\u8bcd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  Table_A\n  <strong>LEFT<\/strong> <strong>JOIN<\/strong> Table_B\n<strong>ON<\/strong>\n  Table_A.id = Table_B.student_id\n<strong>UNION<\/strong> <strong>DISTINCT<\/strong>\n<strong>SELECT<\/strong>\n  *\n<strong>FROM<\/strong>\n  Table_A\n  <strong>RIGHT<\/strong> <strong>JOIN<\/strong> Table_B <strong>ON<\/strong> Table_A.id=Table_B.student_id;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u53e5\u8bdd\u76f8\u5f53\u4e8e\u540c\u65f6\u6267\u884c\u4e86A\u3001B\u8868\u7684\u5de6\u53f3\u8fde\u63a5\u3002<\/p>\n\n\n\n<p>UNION\u5173\u952e\u5b57\u53ef\u4ee5\u5c06\u4e24\u4e2a\u67e5\u8be2\u8bed\u53e5\u7684\u7ed3\u679c\u5408\u5e76\uff0c\u5e76\u53bb\u9664\u91cd\u590d\u6570\u636e\uff0cUNION DISTINCT \u548c UNION \u7684\u6548\u679c\u4e00\u6837\uff0c\u6240\u4ee5\u6211\u4eec\u4e00\u822c\u76f4\u63a5\u4f7f\u7528UNION\u3002<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-color has-text-color\">\u4e00\u822c\u6765\u8bf4\u6570\u636e\u90fd\u662f\u9700\u8981\u53bb\u91cd\u7684\uff0c\u4f46\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5c55\u793a\u4e0d\u53bb\u91cd\u7684\u6570\u636e\uff0c\u6b64\u65f6\u53ef\u4ee5\u5427 DISTINCT \u5173\u952e\u8bcd\u6362\u6210 ALL\u3002<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\"><span class=\"has-inline-color has-black-color\">\u7b1b\u5361\u5c14\u79ef<\/span><\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">\u5728\u5b9e\u9645\u5e94\u7528\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u67e5\u8be2\u53ef\u80fd\u51fa\u73b0\u7684\u6240\u6709\u7ed3\u679c\uff0c\u5373A\u3001B\u4e24\u8868\u5185\u6570\u636e\u4e24\u4e24\u7ec4\u5408\u5168\u6392\uff0c\u8fd9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528      cross join \u5173\u952e\u8bcd\u6765\u5b8c\u6210\u3002<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">\u5f53\u7136\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6211\u4eec\u5e94\u8be5\u5c3d\u53ef\u80fd\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u6211\u4eec\u67e5\u8be2\u5982\u8bfe\u7a0b\u4fe1\u606f\u7684\u65f6\u5019\u5f80\u5f80\u9700\u8981\u8fde\u540c\u8bfe\u7a0b\u7684\u5b66\u4e1a\u5bfc\u5e08\u4e00\u540c\u67e5\u8be2\u51fa\u6765\uff0c\u6700\u539f\u59cb\u7684\u65b9\u6cd5\u81ea\u7136\u662f\u5c06\u5b66\u4e1a\u5bfc\u5e08\u7684\u4fe1\u606f\u5355\u72ec\u6dfb\u52a0\u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-713","post","type-post","status-publish","format-standard","hentry","category-6","category-wcd"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/713"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=713"}],"version-history":[{"count":10,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":732,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/713\/revisions\/732"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}