{"id":114,"date":"2024-09-04T17:51:58","date_gmt":"2024-09-04T09:51:58","guid":{"rendered":"https:\/\/wbki.net\/?p=114"},"modified":"2024-09-04T17:54:48","modified_gmt":"2024-09-04T09:54:48","slug":"mysql%e4%b8%ad%e7%9a%84-%e7%b4%a2%e5%bc%95%e3%80%81%e4%b8%bb%e9%94%ae%e3%80%81-innre-join%e3%80%81left-join%e3%80%81right-join-%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/wbki.net\/?p=114","title":{"rendered":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6"},"content":{"rendered":"<div class=\"has-text-align-center wp-block-post-date\"><time datetime=\"2024-09-04T17:51:58+08:00\">2024\u5e74 9\u6708 4\u65e5<\/time><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u7d22\u5f15<\/h2>\n\n\n\n<p><code>KEY '<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">idx<\/mark>_id_name' (<\/code>id<code>, <\/code>name<code>)<\/code>\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u590d\u5408\u7d22\u5f15\uff0c\u5b83\u5305\u542b\u591a\u4e2a\u5217\u3002\u8fd9\u4e2a\u7d22\u5f15\u5c06\u6309\u7167<code>id<\/code>\u548c<code>name<\/code>\u5217\u7684\u987a\u5e8f\u5bf9\u6570\u636e\u8fdb\u884c\u7d22\u5f15\u3002\u5176\u4e2d<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"> idx<\/mark>\u662f\u7d22\u5f15\u7684\u540d\u79f0\uff0c\u662f\u81ea\u5b9a\u4e49\u7684\u3002<\/p>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>CREATE TABLE my_table (<br>    id INT,<br>    name VARCHAR(100),<br>    KEY `idx_id_name` (`id`, `name`)<br>);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3b\u952e<\/h2>\n\n\n\n<p>PRIMARY KEY (user_id) USING BTREE \uff1a\u7528\u4e8e\u5b9a\u4e49\u8868\u4e2d\u4e3b\u952e\u7684\u8bed\u53e5\u5e76\u4e14\u6307\u5b9a\u4f7f\u7528B-tree\u7d22\u5f15\u7c7b\u578b\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>PRIMARY KEY<\/code><\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u7d22\u5f15\uff0c\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u6570\u636e\u3002\u4e00\u4e2a\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e\uff0c\u5b83\u5fc5\u987b\u5305\u542b\u552f\u4e00\u7684\u503c\uff0c\u5e76\u4e14\u4e0d\u80fd\u5305\u542bNULL\u503c\u3002<\/li>\n\n\n\n<li><strong><code>(user_id)<\/code><\/strong>\uff1a\u8fd9\u8868\u793a\u4e3b\u952e\u662f\u7531<code>user_id<\/code>\u8fd9\u4e00\u5217\u6784\u6210\u7684\u3002\u5982\u679c\u4e3b\u952e\u7531\u591a\u4e2a\u5217\u7ec4\u6210\uff0c\u53ef\u4ee5\u5217\u51fa\u591a\u4e2a\u5217\u540d\uff0c\u7528\u9017\u53f7\u5206\u9694\uff0c\u4f8b\u5982<code>(column1, column2)<\/code>\u3002<\/li>\n\n\n\n<li><strong><code>USING BTREE<\/code><\/strong>\uff1a\u8fd9\u662f\u6307\u5b9a\u7d22\u5f15\u7684\u5b58\u50a8\u5f15\u64ce\u7c7b\u578b\u3002\u5728MySQL\u4e2d\uff0cB-tree\uff08\u5e73\u8861\u6811\uff09\u7d22\u5f15\u662f\u6700\u5e38\u7528\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u9002\u7528\u4e8e\u5168\u503c\u5339\u914d\u3001\u8303\u56f4\u67e5\u8be2\u3001\u524d\u7f00\u5339\u914d\u7b49\u573a\u666f\u3002<code>USING BTREE<\/code>\u662f\u53ef\u9009\u7684\uff0c\u56e0\u4e3aInnoDB\u548cMyISAM\u5b58\u50a8\u5f15\u64ce\u9ed8\u8ba4\u4f7f\u7528B-tree\u7d22\u5f15\uff0c\u6240\u4ee5\u5373\u4f7f\u4e0d\u663e\u5f0f\u6307\u5b9a\uff0c\u4e5f\u4f1a\u4f7f\u7528B-tree\u7d22\u5f15\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u793a\u4f8b\uff1a\u5047\u8bbe\u4f60\u6b63\u5728\u521b\u5efa\u4e00\u4e2a\u65b0\u8868\uff0c\u5e76\u4e14\u60f3\u8981\u6307\u5b9a\u4e00\u4e2a\u4e3b\u952e\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE users (\n    user_id INT NOT NULL,\n    username VARCHAR(50) NOT NULL,\n    email VARCHAR(100),\n    PRIMARY KEY (user_id) USING BTREE\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN\u76f8\u5173\u77e5\u8bc6<\/h2>\n\n\n\n<p>\u4e3e\u4f8b\u7406\u89e3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>INNER JOIN<\/code><\/strong>\uff08\u5185\u8fde\u63a5\uff09\uff1a\u8fd9\u5c31\u50cf\u662f\u4f60\u53ea\u5bf9\u90a3\u4e9b\u5728\u4e24\u4e2a\u4e66\u67b6\u4e0a\u90fd\u6709\u7684\u4e66\u611f\u5174\u8da3\u3002\u4f60\u53ea\u4f1a\u628a\u90a3\u4e9b\u5728\u4e66\u67b6A\u548c\u4e66\u67b6B\u4e0a\u90fd\u6709\u7684\u4e66\u62ff\u51fa\u6765\u3002\u5982\u679c\u4e00\u672c\u4e66\u53ea\u5728\u4e00\u4e2a\u4e66\u67b6\u4e0a\uff0c\u90a3\u4e48\u5b83\u5c31\u4e0d\u4f1a\u88ab\u9009\u4e2d\u3002<\/li>\n\n\n\n<li><strong><code>LEFT JOIN<\/code><\/strong>\uff08\u5de6\u8fde\u63a5\uff09\uff1a\u8fd9\u5c31\u50cf\u662f\u4f60\u628a\u4e66\u67b6A\u4e0a\u6240\u6709\u7684\u4e66\u90fd\u62ff\u51fa\u6765\uff0c\u7136\u540e\u53bb\u4e66\u67b6B\u4e0a\u627e\u6709\u6ca1\u6709\u7f16\u53f7\u76f8\u540c\u7684\u4e66\u3002\u5982\u679c\u627e\u5230\u4e86\uff0c\u5c31\u628a\u5b83\u4eec\u653e\u5728\u4e00\u8d77\uff1b\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u4e66\u67b6A\u4e0a\u7684\u4e66\u4ecd\u7136\u4f1a\u88ab\u62ff\u51fa\u6765\uff0c\u53ea\u662f\u65c1\u8fb9\u6ca1\u6709\u4e66\u67b6B\u4e0a\u7684\u4e66\u4e0e\u4e4b\u914d\u5bf9\u3002<\/li>\n\n\n\n<li><strong><code>RIGHT JOIN<\/code><\/strong>\uff08\u53f3\u8fde\u63a5\uff09\uff1a\u8fd9\u4e0e<code>LEFT JOIN<\/code>\u76f8\u53cd\u3002\u4f60\u9996\u5148\u628a\u4e66\u67b6B\u4e0a\u6240\u6709\u7684\u4e66\u90fd\u62ff\u51fa\u6765\uff0c\u7136\u540e\u53bb\u4e66\u67b6A\u4e0a\u627e\u6709\u6ca1\u6709\u7f16\u53f7\u76f8\u540c\u7684\u4e66\u3002\u5982\u679c\u627e\u5230\u4e86\uff0c\u5c31\u628a\u5b83\u4eec\u653e\u5728\u4e00\u8d77\uff1b\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u4e66\u67b6B\u4e0a\u7684\u4e66\u4ecd\u7136\u4f1a\u88ab\u62ff\u51fa\u6765\uff0c\u53ea\u662f\u65c1\u8fb9\u6ca1\u6709\u4e66\u67b6A\u4e0a\u7684\u4e66\u4e0e\u4e4b\u914d\u5bf9\u3002<\/li>\n\n\n\n<li><strong><code>FULL OUTER JOIN<\/code><\/strong>\uff08\u5168\u5916\u8fde\u63a5\uff09\uff1a\u8fd9\u5c31\u50cf\u662f\u4f60\u628a\u4e24\u4e2a\u4e66\u67b6\u4e0a\u6240\u6709\u7684\u4e66\u90fd\u62ff\u51fa\u6765\uff0c\u7136\u540e\u627e\u51fa\u6240\u6709\u914d\u5bf9\u7684\u4e66\u653e\u5728\u4e00\u8d77\uff0c\u540c\u65f6\u4e5f\u4f1a\u5305\u62ec\u90a3\u4e9b\u53ea\u5728\u4e00\u4e2a\u4e66\u67b6\u4e0a\u7684\u4e66\u3002\u8fd9\u79cd\u8fde\u63a5\u4f1a\u663e\u793a\u4e24\u4e2a\u4e66\u67b6\u4e0a\u6240\u6709\u7684\u4e66\uff0c\u65e0\u8bba\u5b83\u4eec\u662f\u5426\u914d\u5bf9\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5728MySQL\u4e2d\uff0c<code>INNER JOIN<\/code>\u3001<code>LEFT JOIN<\/code>\u548c<code>RIGHT JOIN<\/code>\u662f\u6700\u5e38\u7528\u7684\uff0c\u800c<code>FULL OUTER JOIN<\/code>\u4e0d\u662fMySQL\u76f4\u63a5\u652f\u6301\u7684\uff0c\u4f46\u4f60\u53ef\u4ee5\u901a\u8fc7\u7ed3\u5408<code>LEFT JOIN<\/code>\u548c<code>RIGHT JOIN<\/code>\u4ee5\u53ca<code>UNION<\/code>\u6765\u6a21\u62df\u5b83\u3002<\/p>\n\n\n\n<p>\u6a21\u62df\u64cd\u4f5c\uff1a\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u8868\uff1a<code>books_a<\/code> \u548c <code>books_b<\/code>\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8868\u4e2d\u90fd\u6709\u4e00\u4e2a\u540d\u4e3a<code>book_id<\/code>\u7684\u5217\u3002<\/p>\n\n\n\n<div class=\"wp-block-group is-content-justification-center is-nowrap is-layout-flex wp-container-core-group-is-layout-94bc23d7 wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code><code>books_a<\/code>\n+---------+\n| book_id |\n+---------+\n| A1      |\n| A2      |\n| A3      |\n+---------+<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group is-content-justification-center is-nowrap is-layout-flex wp-container-core-group-is-layout-94bc23d7 wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code>books_b\n\n+---------+\n| book_id |\n+---------+\n| B1      |\n| A2      |\n| B3      |\n+---------+<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p><strong><code>INNER JOIN<\/code><\/strong>\uff1a\u627e\u51fa\u4e24\u4e2a\u8868\u4e2d<code>book_id<\/code>\u76f8\u540c\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a.book_id, b.book_id\nFROM books_a a\nINNER JOIN books_b b ON a.book_id = b.book_id;<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\uff1a<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| book_id | book_id |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| A2           | A2        |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<\/p>\n\n\n\n<p><strong><code>LEFT JOIN<\/code><\/strong>\uff1a\u8fd4\u56de<code>books_a<\/code>\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4ee5\u53ca\u5728<code>books_b<\/code>\u4e2d\u627e\u5230\u7684\u5339\u914d\u8bb0\u5f55\u3002\u5982\u679c<code>books_b<\/code>\u4e2d\u6ca1\u6709\u5339\u914d\u7684\u8bb0\u5f55\uff0c\u5bf9\u5e94\u7684\u5217\u5c06\u663e\u793a\u4e3a<code>NULL<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a.book_id, b.book_id\nFROM books_a a\nLEFT JOIN books_b b ON a.book_id = b.book_id;<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| book_id | book_id |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| A1          | NULL      |<br>| A2          | A2          |<br>| A3          | NULL      |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<\/p>\n\n\n\n<p><strong><code>RIGHT JOIN<\/code><\/strong>\uff1a\u8fd4\u56de<code>books_b<\/code>\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4ee5\u53ca\u5728<code>books_a<\/code>\u4e2d\u627e\u5230\u7684\u5339\u914d\u8bb0\u5f55\u3002\u5982\u679c<code>books_a<\/code>\u4e2d\u6ca1\u6709\u5339\u914d\u7684\u8bb0\u5f55\uff0c\u5bf9\u5e94\u7684\u5217\u5c06\u663e\u793a\u4e3a<code>NULL<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a.book_id, b.book_id<br>FROM books_a a<br>RIGHT JOIN books_b b ON a.book_id = b.book_id;<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| book_id | book_id |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<br>| NULL      | B1         |<br>| A2          | A2         |<br>| NULL      | B3         |<br>+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+<\/p>\n\n\n\n<p>FULL OUTER JOIN\uff08\u6a21\u62df\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a.book_id, b.book_id\nFROM books_a a\nLEFT JOIN books_b b ON a.book_id = b.book_id\n\nUNION\n\nSELECT a.book_id, b.book_id\nFROM books_a a\nRIGHT JOIN books_b b ON a.book_id = b.book_id\nWHERE a.book_id IS NULL;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u53ea\u89e3\u91ca\u4e00\u4e0b <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">UNION<\/mark><\/strong> \u5173\u952e\u5b57 : <code>UNION<\/code>\u662f\u4e00\u4e2a\u7528\u6765\u5408\u5e76\u4e24\u4e2a\u6216\u591a\u4e2a<code>SELECT<\/code>\u8bed\u53e5\u7684\u7ed3\u679c\u96c6\u7684\u64cd\u4f5c\u7b26\u3002\u4f7f\u7528<code>UNION<\/code>\u65f6\uff0c\u5b83\u4f1a\u79fb\u9664\u7ed3\u679c\u96c6\u4e2d\u7684\u91cd\u590d\u884c\uff0c\u53ea\u4fdd\u7559\u552f\u4e00\u7684\u8bb0\u5f55\u3002<strong>\u5982\u679c\u4f60\u60f3\u4fdd\u7559\u6240\u6709\u884c\uff0c\u5305\u62ec\u91cd\u590d\u7684\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528<code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">UNION ALL<\/mark><\/code><\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\u70b9\uff1a<\/strong><\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u4f7f\u7528\u591a\u4e2a<code>LEFT JOIN<\/code>\uff08\u5de6\u8fde\u63a5\uff09\u6765\u8fde\u63a5\u591a\u4e2a\u8868\uff0c&#8221;\u5de6\u8868&#8221; \u7684\u6982\u5ff5\u662f\u57fa\u4e8e\u6700\u8fd1\u7684 <code>JOIN<\/code> \u64cd\u4f5c<\/mark><\/strong><\/p>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n    *\nFROM\n    orders o\nLEFT JOIN customers c ON o.customer_id = c.customer_id\nLEFT JOIN products p ON o.product_id = p.product_id;<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u4e2a <code>LEFT JOIN<\/code> \u662f\u5728 <code>orders<\/code> \u8868\uff08\u522b\u540d <code>o<\/code>\uff09\u548c <code>customers<\/code> \u8868\uff08\u522b\u540d <code>c<\/code>\uff09\u4e4b\u95f4\u8fdb\u884c\u7684\u3002\u5728\u8fd9\u91cc\uff0c<code>orders<\/code> \u8868\u662f &#8220;\u5de6\u8868&#8221;\uff0c<code>customers<\/code> \u8868\u662f &#8220;\u53f3\u8868&#8221;\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e8c\u4e2a <code>LEFT JOIN<\/code> \u662f\u5728\u7ed3\u679c\u96c6\u7684\u57fa\u7840\u4e0a\uff0c\u518d\u4e0e <code>products<\/code> \u8868\uff08\u522b\u540d <code>p<\/code>\uff09\u8fdb\u884c\u8fde\u63a5\u3002\u8fd9\u91cc\u7684 &#8220;\u5de6\u8868&#8221; \u662f\u7b2c\u4e00\u4e2a <code>LEFT JOIN<\/code> \u7684\u7ed3\u679c\u96c6\uff0c\u800c\u4e0d\u662f\u5355\u72ec\u6307 <code>orders<\/code> \u6216 <code>customers<\/code> \u8868\u3002&#8221;\u53f3\u8868&#8221; \u662f <code>products<\/code> \u8868\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6240\u4ee5\uff0c\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a <code>LEFT JOIN<\/code> \u6765\u8bf4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5de6\u8868<\/strong>\uff1a\u662f\u7b2c\u4e00\u4e2a\u00a0<code>LEFT JOIN<\/code>\u00a0\u7684\u7ed3\u679c\u96c6\uff0c\u5373\u5305\u62ec\u00a0<code>orders<\/code>\u00a0\u548c\u00a0<code>customers<\/code>\u00a0\u7684\u8054\u5408\u7ed3\u679c\u3002<\/li>\n\n\n\n<li><strong>\u53f3\u8868<\/strong>\uff1a\u662f\u00a0<code>products<\/code>\u00a0\u8868\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u4e2a &#8220;\u5de6\u8868&#8221; \u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u4e2d\u95f4\u7ed3\u679c\u96c6\uff0c\u5b83\u5305\u542b\u4e86 <code>orders<\/code> \u8868\u548c <code>customers<\/code> \u8868\u7684\u8054\u5408\u6570\u636e\uff0c\u7136\u540e\u8fd9\u4e2a\u4e2d\u95f4\u7ed3\u679c\u96c6\u518d\u4e0e <code>products<\/code> \u8868\u8fdb\u884c <code>LEFT JOIN<\/code>\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u96c6\u4e2d\u4f1a\u5305\u542b\u4ee5\u4e0b\u51e0\u90e8\u5206\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>orders<\/code>\u00a0\u8868\u7684\u6240\u6709\u5217\u3002<\/li>\n\n\n\n<li><code>customers<\/code>\u00a0\u8868\u7684\u6240\u6709\u5217\uff0c\u4f46\u53ea\u6709\u5f53\u00a0<code>orders<\/code>\u00a0\u8868\u4e2d\u7684\u00a0<code>customer_id<\/code>\u00a0\u4e0e\u00a0<code>customers<\/code>\u00a0\u8868\u4e2d\u7684\u00a0<code>customer_id<\/code>\u00a0\u5339\u914d\u65f6\uff0c\u624d\u4f1a\u663e\u793a\u00a0<code>customers<\/code>\u00a0\u8868\u7684\u6570\u636e\uff0c\u5426\u5219\u5bf9\u5e94\u7684\u5217\u4f1a\u7528\u00a0<code>NULL<\/code>\u00a0\u586b\u5145\u3002<\/li>\n\n\n\n<li><code>products<\/code>\u00a0\u8868\u7684\u6240\u6709\u5217\uff0c\u4f46\u53ea\u6709\u5f53\u00a0<code>orders<\/code>\u00a0\u8868\u4e2d\u7684\u00a0<code>product_id<\/code>\u00a0\u4e0e\u00a0<code>products<\/code>\u00a0\u8868\u4e2d\u7684\u00a0<code>product_id<\/code>\u00a0\u5339\u914d\u65f6\uff0c\u624d\u4f1a\u663e\u793a\u00a0<code>products<\/code>\u00a0\u8868\u7684\u6570\u636e\uff0c\u5426\u5219\u5bf9\u5e94\u7684\u5217\u4f1a\u7528\u00a0<code>NULL<\/code>\u00a0\u586b\u5145\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4fee\u6539\u65e5\u671f\uff1a<\/p>\n\n\n<div class=\"wp-block-post-date__modified-date wp-block-post-date\"><time datetime=\"2024-09-04T17:54:48+08:00\">2024\u5e74 9\u6708 4\u65e5<\/time><\/div>\n\n<div class=\"wp-block-post-author\"><div class=\"wp-block-post-author__avatar\"><img alt='' src='https:\/\/secure.gravatar.com\/avatar\/417ce1b39f506666aa6d7384096392d377be7cab868b6daf24c3c9ffa3b631ea?s=48&#038;d=mm&#038;r=g' srcset='https:\/\/secure.gravatar.com\/avatar\/417ce1b39f506666aa6d7384096392d377be7cab868b6daf24c3c9ffa3b631ea?s=96&#038;d=mm&#038;r=g 2x' class='avatar avatar-48 photo' height='48' width='48' \/><\/div><div class=\"wp-block-post-author__content\"><p class=\"wp-block-post-author__byline\">\u4e07\u522b\u5ba2<\/p><p class=\"wp-block-post-author__name\">Brother_Wan<\/p><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>\u7d22\u5f15 KEY &#8216;idx_id_name&#8217; (id, name)\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u590d\u5408\u7d22\u5f15\uff0c\u5b83\u5305\u542b\u591a\u4e2a\u5217\u3002\u8fd9\u4e2a\u7d22\u5f15\u5c06&#8230;<\/p>\n","protected":false},"author":1,"featured_media":116,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,7],"tags":[],"class_list":["post-114","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-programming-language"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wbki.net\/?p=114\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b\" \/>\n<meta property=\"og:description\" content=\"\u7d22\u5f15 KEY &#039;idx_id_name&#039; (id, name)\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u590d\u5408\u7d22\u5f15\uff0c\u5b83\u5305\u542b\u591a\u4e2a\u5217\u3002\u8fd9\u4e2a\u7d22\u5f15\u5c06...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wbki.net\/?p=114\" \/>\n<meta property=\"og:site_name\" content=\"\u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-04T09:51:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-04T09:54:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1472\" \/>\n\t<meta property=\"og:image:height\" content=\"758\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Brother_Wan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brother_Wan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/wbki.net\/?p=114#article\",\"isPartOf\":{\"@id\":\"https:\/\/wbki.net\/?p=114\"},\"author\":{\"name\":\"Brother_Wan\",\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8\"},\"headline\":\"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6\",\"datePublished\":\"2024-09-04T09:51:58+00:00\",\"dateModified\":\"2024-09-04T09:54:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/wbki.net\/?p=114\"},\"wordCount\":89,\"publisher\":{\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8\"},\"image\":{\"@id\":\"https:\/\/wbki.net\/?p=114#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png\",\"articleSection\":[\"Mysql\",\"\u7f16\u7a0b\u8bed\u8a00\u77e5\u8bc6\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wbki.net\/?p=114\",\"url\":\"https:\/\/wbki.net\/?p=114\",\"name\":\"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b\",\"isPartOf\":{\"@id\":\"https:\/\/wbki.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wbki.net\/?p=114#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wbki.net\/?p=114#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png\",\"datePublished\":\"2024-09-04T09:51:58+00:00\",\"dateModified\":\"2024-09-04T09:54:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/wbki.net\/?p=114#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wbki.net\/?p=114\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/wbki.net\/?p=114#primaryimage\",\"url\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png\",\"contentUrl\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png\",\"width\":1472,\"height\":758},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wbki.net\/?p=114#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/wbki.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wbki.net\/#website\",\"url\":\"https:\/\/wbki.net\/\",\"name\":\"\u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b\",\"description\":\"\u4e07\u522b\u5ba2\u7684\u65e5\u8bb0\",\"publisher\":{\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wbki.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8\",\"name\":\"Brother_Wan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/02\/deddc670-d587-4881-acfc-4eab94c91754.jpg\",\"contentUrl\":\"https:\/\/wbki.net\/wp-content\/uploads\/2024\/02\/deddc670-d587-4881-acfc-4eab94c91754.jpg\",\"width\":1024,\"height\":1024,\"caption\":\"Brother_Wan\"},\"logo\":{\"@id\":\"https:\/\/wbki.net\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/wbki.net\"],\"url\":\"https:\/\/wbki.net\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wbki.net\/?p=114","og_locale":"zh_CN","og_type":"article","og_title":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b","og_description":"\u7d22\u5f15 KEY 'idx_id_name' (id, name)\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u590d\u5408\u7d22\u5f15\uff0c\u5b83\u5305\u542b\u591a\u4e2a\u5217\u3002\u8fd9\u4e2a\u7d22\u5f15\u5c06...","og_url":"https:\/\/wbki.net\/?p=114","og_site_name":"\u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b","article_published_time":"2024-09-04T09:51:58+00:00","article_modified_time":"2024-09-04T09:54:48+00:00","og_image":[{"width":1472,"height":758,"url":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png","type":"image\/png"}],"author":"Brother_Wan","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"Brother_Wan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wbki.net\/?p=114#article","isPartOf":{"@id":"https:\/\/wbki.net\/?p=114"},"author":{"name":"Brother_Wan","@id":"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8"},"headline":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6","datePublished":"2024-09-04T09:51:58+00:00","dateModified":"2024-09-04T09:54:48+00:00","mainEntityOfPage":{"@id":"https:\/\/wbki.net\/?p=114"},"wordCount":89,"publisher":{"@id":"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8"},"image":{"@id":"https:\/\/wbki.net\/?p=114#primaryimage"},"thumbnailUrl":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png","articleSection":["Mysql","\u7f16\u7a0b\u8bed\u8a00\u77e5\u8bc6"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"https:\/\/wbki.net\/?p=114","url":"https:\/\/wbki.net\/?p=114","name":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6 - \u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b","isPartOf":{"@id":"https:\/\/wbki.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wbki.net\/?p=114#primaryimage"},"image":{"@id":"https:\/\/wbki.net\/?p=114#primaryimage"},"thumbnailUrl":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png","datePublished":"2024-09-04T09:51:58+00:00","dateModified":"2024-09-04T09:54:48+00:00","breadcrumb":{"@id":"https:\/\/wbki.net\/?p=114#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wbki.net\/?p=114"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/wbki.net\/?p=114#primaryimage","url":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png","contentUrl":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/09\/Mysql\u4e2d\u7684-\u7d22\u5f15\u3001\u4e3b\u952e\u3001-INNRE-JOIN\u3001LEFT-JOIN\u3001RIGHT-JOIN-\u77e5\u8bc6.png","width":1472,"height":758},{"@type":"BreadcrumbList","@id":"https:\/\/wbki.net\/?p=114#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/wbki.net\/"},{"@type":"ListItem","position":2,"name":"Mysql\u4e2d\u7684 \u7d22\u5f15\u3001\u4e3b\u952e\u3001 INNRE JOIN\u3001LEFT JOIN\u3001RIGHT JOIN \u77e5\u8bc6"}]},{"@type":"WebSite","@id":"https:\/\/wbki.net\/#website","url":"https:\/\/wbki.net\/","name":"\u4e07\u522b\u5ba2\u7684\u767e\u5b9d\u888b","description":"\u4e07\u522b\u5ba2\u7684\u65e5\u8bb0","publisher":{"@id":"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wbki.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/wbki.net\/#\/schema\/person\/a18e9ddc78771da747372ebb77735bd8","name":"Brother_Wan","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/wbki.net\/#\/schema\/person\/image\/","url":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/02\/deddc670-d587-4881-acfc-4eab94c91754.jpg","contentUrl":"https:\/\/wbki.net\/wp-content\/uploads\/2024\/02\/deddc670-d587-4881-acfc-4eab94c91754.jpg","width":1024,"height":1024,"caption":"Brother_Wan"},"logo":{"@id":"https:\/\/wbki.net\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/wbki.net"],"url":"https:\/\/wbki.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wbki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":1,"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/115"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wbki.net\/index.php?rest_route=\/wp\/v2\/media\/116"}],"wp:attachment":[{"href":"https:\/\/wbki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wbki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wbki.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}