{"id":5450,"date":"2025-07-30T01:33:33","date_gmt":"2025-07-29T16:33:33","guid":{"rendered":"https:\/\/sky-peace.net\/?p=5450"},"modified":"2025-07-30T01:33:33","modified_gmt":"2025-07-29T16:33:33","slug":"db-cte","status":"publish","type":"post","link":"https:\/\/sky-peace.net\/certified\/db-cte\/","title":{"rendered":"WITH RECURSIVE\u3067\u7406\u89e3\u3059\u308b\u518d\u5e30\u7684SQL\u306e\u57fa\u672c\u3068\u843d\u3068\u3057\u7a74\u2502\u5fdc\u7528\u60c5\u5831\u5348\u5f8c\u5bfe\u7b56"},"content":{"rendered":"<p>SQL\u306b\u306f\u3055\u307e\u3056\u307e\u306a\u69cb\u6587\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u300c\u518d\u5e30\u7684SQL\u300d\u306f\u4e00\u6b69\u9032\u3093\u3060\u7406\u89e3\u304c\u6c42\u3081\u3089\u308c\u308b\u9818\u57df\u3067\u3059\u3002\u7279\u306b\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306a\u3069\u306e\u5348\u5f8c\u8a66\u9a13\u3067\u306f\u3001\u30c4\u30ea\u30fc\u69cb\u9020\u3084\u968e\u5c64\u69cb\u9020\u306e\u30c7\u30fc\u30bf\u64cd\u4f5c\u306b\u95a2\u9023\u3057\u3066\u3001<code>WITH RECURSIVE<\/code>\u53e5\u3092\u7528\u3044\u305f\u554f\u984c\u304c\u3057\u3070\u3057\u3070\u51fa\u984c\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u300c\u305d\u3082\u305d\u3082\u518d\u5e30\u7684SQL\u3068\u306f\u4f55\u304b\uff1f\u300d\u300c<code>WITH RECURSIVE<\/code>\u3067\u4f55\u304c\u3067\u304d\u308b\u306e\u304b\uff1f\u300d\u300c\u4f7f\u3044\u3069\u3053\u308d\u3068\u907f\u3051\u308b\u3079\u304d\u30b1\u30fc\u30b9\u306f\uff1f\u300d\u3068\u3044\u3063\u305f\u57fa\u672c\u7684\u306a\u7591\u554f\u306b\u52a0\u3048\u3001\u300c\u5b9f\u969b\u306e\u8a66\u9a13\u3067\u554f\u308f\u308c\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8\u300d\u300c\u9593\u9055\u3048\u3084\u3059\u3044\u9078\u629e\u80a2\u300d\u306a\u3069\u3092\u660e\u3089\u304b\u306b\u3057\u306a\u304c\u3089\u3001\u5b66\u7fd2\u8005\u304c\u3064\u307e\u305a\u304d\u3084\u3059\u3044\u201c\u518d\u5e30\u201d\u3068\u3044\u3046\u30c6\u30fc\u30de\u3092\u89e3\u304d\u307b\u3050\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001<strong>\u4f53\u7cfb\u7684\u306a\u6574\u7406\uff08A\u30b9\u30bf\u30a4\u30eb\uff09<\/strong>\u306b\u52a0\u3048\u3001<strong>\u8eab\u8fd1\u306a\u4f8b\u3048\uff08C\uff09<\/strong>\u3084<strong>\u8077\u5834\u306e\u69cb\u9020\uff08D\uff09<\/strong>\u3001<strong>\u4e2d\u5b66\u751f\u3067\u3082\u5206\u304b\u308b\u4f1a\u8a71\u5f62\u5f0f\uff08E\uff09<\/strong>\u306a\u3069\u3092\u7528\u3044\u3001\u7406\u89e3\u3068\u5b9f\u8df5\u529b\u306e\u4e21\u65b9\u3092\u935b\u3048\u307e\u3059\u3002\u3055\u3089\u306b<strong>\u56f3\u89e3\u30fb\u8868\u30fb\u5177\u4f53\u4f8b<\/strong>\u3082\u6d3b\u7528\u3057\u3001\u5348\u5f8c\u8a66\u9a13\u3067\u5dee\u304c\u3064\u304f\u201c\u518d\u5e30\u7684SQL\u201d\u3092\u5b8c\u5168\u653b\u7565\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u518d\u5e30\u7684SQL\u3068\u306f\u4f55\u304b\uff1f\u2502WITH RECURSIVE\u53e5\u306e\u57fa\u672c\u69cb\u9020\u3068\u8003\u3048\u65b9<\/h2>\n<p>\u300c\u518d\u5e30\u7684SQL\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u805e\u304f\u3068\u3001\u5c11\u3057\u96e3\u3057\u305d\u3046\u306a\u5370\u8c61\u3092\u53d7\u3051\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u672c\u8cea\u7684\u306b\u306f\u300c\u3042\u308b\u51e6\u7406\u3092\u7e70\u308a\u8fd4\u3057\u3066\u968e\u5c64\u7684\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u300d\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4f1a\u793e\u306e\u7d44\u7e54\u69cb\u9020\u3092\u60f3\u50cf\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u3042\u308b\u793e\u54e1\u306e\u4e0a\u53f8\u3092\u305f\u3069\u308b\u3068\u3001\u305d\u306e\u4e0a\u306b\u3082\u3055\u3089\u306b\u4e0a\u53f8\u304c\u3044\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u300c\u968e\u5c64\u300d\u304c\u3042\u308b\u30c7\u30fc\u30bf\u3092\u6271\u3046\u3068\u304d\u3001<strong>\u5f93\u6765\u306eSQL\uff08JOIN\u3084\u30b5\u30d6\u30af\u30a8\u30ea\uff09\u3067\u306f\u300c\u4f55\u968e\u5c64\u3042\u308b\u304b\u300d\u304c\u4e8b\u524d\u306b\u5206\u304b\u3063\u3066\u3044\u306a\u3044\u3068\u3001\u3059\u3079\u3066\u306e\u968e\u5c64\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3002<\/strong><\/p>\n<p>\u305f\u3068\u3048\u30703\u968e\u5c64\u307e\u3067\u306a\u3089JOIN\u30923\u56de\u91cd\u306d\u308c\u3070\u3044\u3044\u3067\u3059\u304c\u30015\u968e\u5c64\u304b10\u968e\u5c64\u304b\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u3001\u4e8b\u524d\u306b\u4f55\u56deJOIN\u3059\u3079\u304d\u304b\u5206\u304b\u3089\u305a\u3001SQL\u304c\u66f8\u3051\u307e\u305b\u3093\u3002\u3053\u3053\u3067\u6d3b\u8e8d\u3059\u308b\u306e\u304c<code>WITH RECURSIVE<\/code>\u53e5\u3067\u3059\u3002<\/p>\n<p><code>WITH RECURSIVE<\/code>\u3092\u4f7f\u3046\u3068\u3001\u521d\u671f\u72b6\u614b\u304b\u30891\u968e\u5c64\u305a\u3064\u518d\u5e30\u7684\u306b\u51e6\u7406\u3092\u7e70\u308a\u8fd4\u3057\u3001\u81ea\u52d5\u7684\u306b\u5168\u968e\u5c64\u3092\u8d70\u67fb\u3067\u304d\u307e\u3059\u3002\u3064\u307e\u308a<strong>\u300c\u968e\u5c64\u306e\u6df1\u3055\u304c\u4e0d\u660e\u3067\u3082\u3001\u3059\u3079\u3066\u306e\u89aa\u5b50\u95a2\u4fc2\u3092\u8fbf\u308c\u308b\u300d\u306e\u304c\u6700\u5927\u306e\u5f37\u307f<\/strong>\u306a\u306e\u3067\u3059\u3002<\/p>\n<h3>\u25a0 WITH RECURSIVE\u53e5\u3068\u306f\uff1f<\/h3>\n<p><code>WITH RECURSIVE<\/code> \u53e5\u306f\u3001\u81ea\u5df1\u53c2\u7167\uff08\u518d\u5e30\uff09\u3059\u308b\u3088\u3046\u306a\u30af\u30a8\u30ea\u3092\u8a18\u8ff0\u3059\u308b\u305f\u3081\u306eSQL\u69cb\u6587\u3067\u3059\u3002\u4ee5\u4e0b\u306e2\u3064\u306e\u30d1\u30fc\u30c8\u3067\u69cb\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u30d1\u30fc\u30c8\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u30a2\u30f3\u30ab\u30fc\u90e8\uff08\u521d\u671f\u5024\uff09<\/strong><\/td>\n<td>\u518d\u5e30\u306e\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3068\u306a\u308b\u30c7\u30fc\u30bf\uff08\u4f8b\uff1a\u6700\u4e0a\u4f4d\u306e\u793e\u54e1\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u518d\u5e30\u90e8<\/strong><\/td>\n<td>\u30a2\u30f3\u30ab\u30fc\u306e\u7d50\u679c\u3092\u57fa\u306b\u3001\u3055\u3089\u306b1\u968e\u5c64\u305a\u3064\u4e0b\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u3044\u304f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u308c\u3089\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u3067\u3001SQL\u81ea\u8eab\u304c\u30eb\u30fc\u30d7\u3092\u56de\u3059\u3088\u3046\u306b\u52d5\u4f5c\u3057\u3001\u968e\u5c64\u30c7\u30fc\u30bf\u30921\u884c\u305a\u3064\u4e0b\u3063\u3066\u53d6\u5f97\u3057\u3066\u3044\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u57fa\u672c\u69cb\u9020\uff08\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\uff09<\/h3>\n<pre><code>WITH RECURSIVE \u968e\u5c64\u540d(\u52171, \u52172, ...) AS (\n    -- \u30a2\u30f3\u30ab\u30fc\u90e8\uff08\u521d\u671f\u72b6\u614b\uff09\n    SELECT ...\n    FROM ...\n    WHERE \u6761\u4ef6\n\n    UNION ALL\n\n    -- \u518d\u5e30\u90e8\uff08\u6b21\u306e\u968e\u5c64\uff09\n    SELECT ...\n    FROM \u5143\u30c6\u30fc\u30d6\u30eb JOIN \u968e\u5c64\u540d\n    ON \u7d50\u5408\u6761\u4ef6\n)\nSELECT * FROM \u968e\u5c64\u540d;\n<\/code><\/pre>\n<h3>\u25a0 \u8eab\u8fd1\u306a\u4f8b\u3048\uff1a\u5bb6\u7cfb\u56f3\u3092\u305f\u3069\u308b<\/h3>\n<p>\u5bb6\u65cf\u306e\u5bb6\u7cfb\u56f3\u3092\u60f3\u50cf\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3042\u306a\u305f\u306e\u7956\u7236\u6bcd\u3092\u8abf\u3079\u3001\u305d\u3053\u304b\u3089\u89aa\u2192\u81ea\u5206\u2192\u5b50\u2192\u5b6b\u2026\u3068\u4e16\u4ee3\u3092\u4e0b\u3063\u3066\u3044\u304f\u306e\u304c\u518d\u5e30\u51e6\u7406\u306e\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u30021\u56de\u3067\u5168\u54e1\u3092\u898b\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u300c1\u30b9\u30c6\u30c3\u30d7\u305a\u3064\u4e0b\u3078\u4e0b\u3078\u300d\u3068\u964d\u308a\u3066\u3044\u304f\u306e\u304c\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<h3>\u901a\u5e38\u306eWITH\uff08CTE\uff09\u3068\u306f<\/h3>\n<p>SQL\u306e <strong>CTE\uff08Common Table Expression: \u5171\u901a\u30c6\u30fc\u30d6\u30eb\u5f0f\uff09<\/strong> \u306f\u3001<code>WITH \uff5e AS (...)<\/code> \u306e\u5f62\u3067\u4e00\u6642\u7684\u306a\u7d50\u679c\u30bb\u30c3\u30c8\u306b\u540d\u524d\u3092\u3064\u3051\u3001\u30af\u30a8\u30ea\u306e\u4e2d\u3067\u518d\u5229\u7528\u3067\u304d\u308b\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\nWITH cte_sales AS (\n  SELECT customer_id, SUM(amount) AS total\n  FROM sales\n  GROUP BY customer_id\n)\nSELECT *\nFROM cte_sales\nWHERE total &gt; 1000;\n<\/code><\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001<code>cte_sales<\/code> \u304c\u4e00\u6642\u7684\u306a\u300c\u4eee\u60f3\u30c6\u30fc\u30d6\u30eb\u300d\u3068\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>WITH RECURSIVE\u306fCTE\u306e\u62e1\u5f35\u7248<\/h3>\n<p>\u901a\u5e38\u306e <code>WITH<\/code> \u306f\u5358\u7d14\u306a\u4e00\u6642\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\u3067\u3059\u304c\u3001<strong><code>WITH RECURSIVE<\/code> \u306f\u300c\u81ea\u5df1\u53c2\u7167\u3067\u304d\u308bCTE\u300d<\/strong> \u3092\u4f5c\u308b\u305f\u3081\u306e\u62e1\u5f35\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<ul>\n<li><code>WITH<\/code> \u2026 \u4e00\u5ea6\u4f5c\u3063\u305f\u3089\u4f7f\u3046\u3060\u3051<\/li>\n<li><code>WITH RECURSIVE<\/code> \u2026 \u81ea\u5206\u81ea\u8eab\u3092\u547c\u3073\u51fa\u3057\u306a\u304c\u3089\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3067\u304d\u308b<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001<code>WITH RECURSIVE<\/code> \u306f <strong>CTE\u306e\u6d3e\u751f\u5f62<\/strong> \u3068\u8a00\u3048\u307e\u3059\u3002<\/p>\n<h3>\u306a\u305c\u5fc5\u8981\u304b\uff1f<\/h3>\n<p>\u89aa\u5b50\u95a2\u4fc2\u3084\u968e\u5c64\u69cb\u9020\u3092\u6301\u3064\u30c7\u30fc\u30bf\uff08\u7d44\u7e54\u30c4\u30ea\u30fc\u3001\u30ab\u30c6\u30b4\u30ea\u968e\u5c64\u306a\u3069\uff09\u3092\u6271\u3046\u3068\u304d\u306b\u6709\u52b9\u3067\u3059\u3002<br \/>\n<code>WITH RECURSIVE<\/code> \u3092\u4f7f\u3046\u3068\u3001<strong>\u89aa \u2192 \u5b50 \u2192 \u5b6b<\/strong> \u3068\u3044\u3063\u305f\u69cb\u9020\u3092\u30b7\u30f3\u30d7\u30eb\u306aSQL\u3067\u305f\u3069\u308c\u307e\u3059\u3002<\/p>\n<h3>\u5177\u4f53\u4f8b\uff1a\u30ab\u30c6\u30b4\u30ea\u306e\u968e\u5c64\u53d6\u5f97<\/h3>\n<pre><code class=\"language-sql\">\nWITH RECURSIVE hierarchy AS (\n  -- \u57fa\u70b9\uff08\u89aa\uff09\n  SELECT id, parent_id, name, 1 AS level\n  FROM categories\n  WHERE parent_id IS NULL\n\n  UNION ALL\n\n  -- \u518d\u5e30\uff08\u5b50\u3092\u305f\u3069\u308b\uff09\n  SELECT c.id, c.parent_id, c.name, h.level + 1\n  FROM categories c\n  INNER JOIN hierarchy h ON c.parent_id = h.id\n)\nSELECT * FROM hierarchy;\n<\/code><\/pre>\n<p>\u3053\u306e\u30af\u30a8\u30ea\u3067\u306f\u3001<code>hierarchy<\/code> \u304cCTE\u540d\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u3001<br \/>\n\u89aa\u30ab\u30c6\u30b4\u30ea\u304b\u3089\u5b50\u30ab\u30c6\u30b4\u30ea\u3001\u3055\u3089\u306b\u5b6b\u30ab\u30c6\u30b4\u30ea\u307e\u3067\u968e\u5c64\u7684\u306b\u5c55\u958b\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li><div class=\"st-mybox  has-title st-mybox-class\" style=\"background:#fafafa;border-width:0px;border-radius:5px;margin: 25px 0 25px 0;\"><p class=\"st-mybox-title\" style=\"color:#757575;font-weight:bold;text-shadow: #fff 3px 0px 0px, #fff 2.83487px 0.981584px 0px, #fff 2.35766px 1.85511px 0px, #fff 1.62091px 2.52441px 0px, #fff 0.705713px 2.91581px 0px, #fff -0.287171px 2.98622px 0px, #fff -1.24844px 2.72789px 0px, #fff -2.07227px 2.16926px 0px, #fff -2.66798px 1.37182px 0px, #fff -2.96998px 0.42336px 0px, #fff -2.94502px -0.571704px 0px, #fff -2.59586px -1.50383px 0px, #fff -1.96093px -2.27041px 0px, #fff -1.11013px -2.78704px 0px, #fff -0.137119px -2.99686px 0px, #fff 0.850987px -2.87677px 0px, #fff 1.74541px -2.43999px 0px, #fff 2.44769px -1.73459px 0px, #fff 2.88051px -0.838246px 0px;background: linear-gradient(0deg,#fafafa 0%,#fafafa 55%,rgba(0,0,0,0) 55%,rgba(0,0,0,0) 100%);\"><i class=\"st-fa st-svg-file-text-o st-css-no\" aria-hidden=\"true\"><\/i>\u307e\u3068\u3081<\/p><div class=\"st-in-mybox\">\n<ul>\n<li><code>WITH<\/code> \u306f\u4e00\u6642\u7684\u306a\u30c6\u30fc\u30d6\u30eb\uff08CTE\uff09\u3092\u4f5c\u308b\u4ed5\u7d44\u307f<\/li>\n<li><code>WITH RECURSIVE<\/code> \u306fCTE\u306e\u6d3e\u751f\u5f62\u3067\u3001\u81ea\u5df1\u53c2\u7167\u306b\u3088\u308b\u518d\u5e30\u51e6\u7406\u304c\u53ef\u80fd<\/li>\n<li>\u968e\u5c64\u30c7\u30fc\u30bf\uff08\u30c4\u30ea\u30fc\u69cb\u9020\u306a\u3069\uff09\u306e\u53d6\u5f97\u306b\u4fbf\u5229<\/li>\n<\/ul>\n<\/div><\/div><\/li>\n<\/ul>\n<h2>WITH RECURSIVE\u306e\u8981\u70b9\u307e\u3068\u3081\uff08CTE\u306e\u6d3e\u751f\u5f62\uff0f\u884c\u304c\u5897\u3048\u308b\u6d41\u308c\uff09<\/h2>\n<h3>1. CTE\u540d\uff08hierarchy\u306a\u3069\uff09\u306b\u3064\u3044\u3066<\/h3>\n<ul>\n<li><code>WITH RECURSIVE hierarchy AS (...)<\/code> \u306e <strong>hierarchy<\/strong> \u306f\u300c\u5171\u901a\u30c6\u30fc\u30d6\u30eb\u5f0f\uff08CTE\uff09\u306e\u540d\u524d\u300d\u3002\u5b9f\u30c6\u30fc\u30d6\u30eb\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/li>\n<li>\u30af\u30a8\u30ea\u5b9f\u884c\u4e2d\u3060\u3051\u5b58\u5728\u3057\u3001<code>FROM hierarchy<\/code> \u306e\u3088\u3046\u306b\u53c2\u7167\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>\u540d\u524d\u306f\u56fa\u5b9a\u3067\u3001<strong>\u5897\u3048\u308b\u306e\u306f\u4e2d\u8eab\u306e\u884c<\/strong>\u3067\u3059\u3002<\/li>\n<\/ul>\n<h3>2. WITH \u3068 WITH RECURSIVE \u306e\u9055\u3044\uff08\u7c21\u6f54\u7248\uff09<\/h3>\n<ul>\n<li><code>WITH<\/code>\uff1a\u4e00\u6642\u7d50\u679c\uff08CTE\uff09\u3092\u5b9a\u7fa9\u3057\u3066\u518d\u5229\u7528\u3059\u308b\u3002<\/li>\n<li><code>WITH RECURSIVE<\/code>\uff1aCTE\u304c<strong>\u81ea\u5df1\u53c2\u7167<\/strong>\u3067\u304d\u3001\u968e\u5c64\u30c7\u30fc\u30bf\u3092\u300c\u89aa\u2192\u5b50\u2192\u5b6b\u2026\u300d\u3068\u6bb5\u968e\u7684\u306b\u5c55\u958b\u3067\u304d\u308b\u3002<\/li>\n<\/ul>\n<h3>3. \u884c\u304c\u3069\u3093\u3069\u3093\u5897\u3048\u308b\u5de5\u7a0b\uff08\u5b9f\u30c7\u30fc\u30bf\u4f8b\u3064\u304d\uff09<\/h3>\n<p>\u5143\u30c6\u30fc\u30d6\u30eb <code>categories<\/code>\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>parent_id<\/th>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>NULL<\/td>\n<td>\u5bb6\u96fb<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>1<\/td>\n<td>\u30c6\u30ec\u30d3<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<td>\u51b7\u8535\u5eab<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>2<\/td>\n<td>4K\u30c6\u30ec\u30d3<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>2<\/td>\n<td>\u6db2\u6676\u30c6\u30ec\u30d3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-sql\">WITH RECURSIVE hierarchy AS (\n  -- \u2460 \u30a2\u30f3\u30ab\u30fc\uff08\u57fa\u70b9\uff09\n  SELECT id, parent_id, name, 1 AS level\n  FROM categories\n  WHERE parent_id IS NULL\n\n  UNION ALL\n\n  -- \u2461 \u518d\u5e30\uff08\u89aa=hierarchy \u306b\u3076\u3089\u4e0b\u304c\u308b\u5b50\u3092\u8ffd\u52a0\uff09\n  SELECT c.id, c.parent_id, c.name, h.level + 1\n  FROM categories AS c\n  JOIN hierarchy  AS h ON c.parent_id = h.id\n)\nSELECT * FROM hierarchy;\n<\/code><\/pre>\n<p>\u5de5\u7a0b\u3054\u3068\u306e <code>hierarchy<\/code> \u306e\u4e2d\u8eab\uff1a<\/p>\n<p><strong>\u5de5\u7a0b\u2460\uff08\u30a2\u30f3\u30ab\u30fc\u5b9f\u884c\u5f8c\uff09<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>parent_id<\/th>\n<th>name<\/th>\n<th>level<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>NULL<\/td>\n<td>\u5bb6\u96fb<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5de5\u7a0b\u2461\uff08\u518d\u5e301\u56de\u76ee\uff1a\u89aa=1\u306e\u5b50\u3092\u8ffd\u52a0\uff09<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>parent_id<\/th>\n<th>name<\/th>\n<th>level<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>NULL<\/td>\n<td>\u5bb6\u96fb<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>1<\/td>\n<td>\u30c6\u30ec\u30d3<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<td>\u51b7\u8535\u5eab<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5de5\u7a0b\u2462\uff08\u518d\u5e302\u56de\u76ee\uff1a\u89aa=2\u306e\u5b50\u3092\u8ffd\u52a0\uff09<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>parent_id<\/th>\n<th>name<\/th>\n<th>level<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>NULL<\/td>\n<td>\u5bb6\u96fb<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>1<\/td>\n<td>\u30c6\u30ec\u30d3<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<td>\u51b7\u8535\u5eab<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>2<\/td>\n<td>4K\u30c6\u30ec\u30d3<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>2<\/td>\n<td>\u6db2\u6676\u30c6\u30ec\u30d3<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5de5\u7a0b\u2463\uff08\u518d\u5e303\u56de\u76ee\uff1a\u65b0\u3057\u3044\u5b50\u304c\u898b\u3064\u304b\u3089\u305a\u7d42\u4e86\uff09<\/strong><br \/>\n\u6700\u7d42\u7684\u306b <code>hierarchy<\/code> \u306b\u306f\u89aa\u2192\u5b50\u2192\u5b6b\u307e\u3067\u306e\u5168\u884c\u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<h3>4. \u306a\u305c JOIN \u304c\u5fc5\u8981\uff1f\uff08\u8981\u70b9\uff09<\/h3>\n<ul>\n<li><code>JOIN<\/code> \u306f\u3001<strong>\u300c\u3059\u3067\u306b\u898b\u3064\u304b\u3063\u305f\u89aa\uff08h.id\uff09\u300d\u306b\u3076\u3089\u4e0b\u304c\u308b\u5b50\uff08<code>c.parent_id<\/code>\uff09\u3060\u3051<\/strong>\u3092\u6b21\u306e\u5de5\u7a0b\u306b\u8ffd\u52a0\u3059\u308b\u305f\u3081\u3002<\/li>\n<li>\u3053\u308c\u306b\u3088\u308a\u3001\u968e\u5c64\u304c<strong>1\u6bb5\u305a\u3064<\/strong>\u6b63\u3057\u304f\u5e83\u304c\u308a\u3001\u5168\u4ef6\u3092\u4e00\u6c17\u306b\u5165\u308c\u3066\u3057\u307e\u3046\u8aa4\u308a\u3092\u9632\u3052\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>5. JOIN\u3057\u3066\u3082\u5217\u304c\u5897\u3048\u306a\u3044\u7406\u7531<\/h3>\n<ul>\n<li><strong>\u5185\u90e8\u3067\u306f\u5897\u3048\u3066\u3044\u308b\uff1a<\/strong> <code>JOIN<\/code> \u6642\u70b9\u3067\u306f <code>categories<\/code> \u3068 <code>hierarchy<\/code> \u306e\u5217\u304c\u7d50\u5408\u3055\u308c\u3001\u4e00\u6642\u7684\u306b\u5217\u306f\u5897\u3048\u307e\u3059\u3002<\/li>\n<li><strong>\u7d50\u679c\u306fSELECT\u3067\u6c7a\u307e\u308b\uff1a<\/strong> \u3057\u304b\u3057\u6700\u7d42\u7684\u306b\u51fa\u529b\u3055\u308c\u308b\u5217\u306f <code>SELECT<\/code> \u53e5\u3067\u6307\u5b9a\u3057\u305f\u3082\u306e\u3060\u3051\uff08\u4f8b\uff1a<code>c.id, c.parent_id, c.name, h.level + 1<\/code>\uff09\u3002\u4e0d\u8981\u306a\u5217\u306f\u51fa\u529b\u3055\u308c\u307e\u305b\u3093\u3002<\/li>\n<li><strong>UNION ALL\u306e\u5236\u7d04\uff1a<\/strong> \u30a2\u30f3\u30ab\u30fc\u90e8\u3068\u518d\u5e30\u90e8\u306f <code>UNION ALL<\/code> \u3067\u7d50\u5408\u3059\u308b\u305f\u3081\u3001<strong>\u5217\u6570\u30fb\u578b\u3092\u4e00\u81f4<\/strong>\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3088\u3063\u3066\u518d\u5e30\u90e8\u3067\u3082\u5217\u306f\u56fa\u5b9a\u306b\u4fdd\u3061\u307e\u3059\u3002<\/li>\n<\/ul>\n<p><em>\u5408\u8a00\u8449\uff1a<\/em> <strong>JOIN \u306f\u300c\u884c\u3092\u6c7a\u3081\u308b\u300d\u30fbSELECT \u306f\u300c\u5217\u3092\u6c7a\u3081\u308b\u300d<\/strong><\/p>\n<h3>6. \u4f7f\u3044\u56de\u3057\u30c6\u30f3\u30d7\u30ec\uff08\u5217\u540d\u306f\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u5909\u66f4\uff09<\/h3>\n<pre><code class=\"language-sql\">WITH RECURSIVE hierarchy (id, parent_id, name, level) AS (\n  SELECT id, parent_id, name, 1\n  FROM categories\n  WHERE parent_id IS NULL\n  UNION ALL\n  SELECT c.id, c.parent_id, c.name, h.level + 1\n  FROM categories AS c\n  JOIN hierarchy  AS h ON c.parent_id = h.id\n)\nSELECT * FROM hierarchy\nORDER BY level, id;\n<\/code><\/pre>\n<h2>WITH RECURSIVE\u53e5\u306e\u5b9f\u884c\u624b\u9806\u3068\u518d\u5e30SQL\u306e\u6d41\u308c\u3092\u56f3\u3067\u7406\u89e3\u3059\u308b<\/h2>\n<p>\u518d\u5e30\u7684SQL\u304c\u3069\u306e\u3088\u3046\u306b\u51e6\u7406\u3092\u9032\u3081\u3066\u3044\u304f\u304b\u306f\u3001\u56f3\u3067\u30a4\u30e1\u30fc\u30b8\u3059\u308b\u3068\u3068\u3066\u3082\u5206\u304b\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001<code>WITH RECURSIVE<\/code>\u53e5\u304c\u3069\u306e\u3088\u3046\u306b\u300c\u521d\u671f\u72b6\u614b\u300d\u304b\u3089\u300c\u518d\u5e30\u30eb\u30fc\u30d7\u300d\u3092\u56de\u3057\u3001\u300c\u7d42\u4e86\u6761\u4ef6\u300d\u306b\u9054\u3059\u308b\u306e\u304b\u3092\u3001\u624b\u9806\u3054\u3068\u306b\u5206\u3051\u3066\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u25a0 \u518d\u5e30SQL\u306e\u51e6\u7406\u30d5\u30ed\u30fc<\/h3>\n<p>\u4ee5\u4e0b\u306f\u3001\u5f93\u696d\u54e1\u306e\u4e0a\u53f8\u2015\u90e8\u4e0b\u95a2\u4fc2\u3092\u8fbf\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<pre><code>\u30b9\u30c6\u30c3\u30d71\uff1a\u30a2\u30f3\u30ab\u30fc\u90e8\u304c\u5b9f\u884c\u3055\u308c\u3001\u6700\u521d\u306e\u884c\uff08\u4f8b\uff1a\u793e\u9577\uff09\u304c\u53d6\u5f97\u3055\u308c\u308b  \n\u3000\u2193  \n\u30b9\u30c6\u30c3\u30d72\uff1a\u518d\u5e30\u90e8\u304c\u5b9f\u884c\u3055\u308c\u30011\u968e\u5c64\u4e0b\u306e\u30c7\u30fc\u30bf\uff08\u793e\u9577\u306e\u90e8\u4e0b\uff09\u304c\u8ffd\u52a0\u3055\u308c\u308b  \n\u3000\u2193  \n\u30b9\u30c6\u30c3\u30d73\uff1a\u3055\u3089\u306b\u305d\u306e\u90e8\u4e0b\u306e\u90e8\u4e0b\u2026\u3068\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u304c\u7d9a\u304f  \n\u3000\u2193  \n\u30b9\u30c6\u30c3\u30d74\uff1a\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3067\u304d\u306a\u304f\u306a\u308b\u307e\u3067\u30eb\u30fc\u30d7\uff08\u30c7\u30fc\u30bf\u304c\u7a7a\u3067\u7d42\u4e86\uff09  \n<\/code><\/pre>\n<h3>\u25a0 \u51e6\u7406\u306e\u9806\u5e8f\uff08\u30c6\u30fc\u30d6\u30eb\u3067\u78ba\u8a8d\uff09<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u30d5\u30a7\u30fc\u30ba<\/th>\n<th>\u5b9f\u884c\u5185\u5bb9<\/th>\n<th>SQL\u306b\u304a\u3051\u308b\u8a72\u5f53\u7b87\u6240<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u30b9\u30bf\u30fc\u30c8<\/td>\n<td>\u30a2\u30f3\u30ab\u30fc\u90e8\u3092\u5b9f\u884c<\/td>\n<td><code>SELECT ... FROM ... WHERE ...<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u30eb\u30fc\u30d71\u56de\u76ee<\/td>\n<td>\u30a2\u30f3\u30ab\u30fc\u7d50\u679c\u3068JOIN\u3057\u3066\u518d\u5e30\u90e8\u3092\u5b9f\u884c<\/td>\n<td><code>UNION ALL SELECT ... JOIN ...<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u30eb\u30fc\u30d72\u56de\u76ee\u4ee5\u964d<\/td>\n<td>\u518d\u5e30\u90e8\u3092\u7e70\u308a\u8fd4\u3057\u5b9f\u884c<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>\u7d42\u4e86\u6761\u4ef6<\/td>\n<td>\u65b0\u3057\u3044\u7d50\u679c\u304c\u8fd4\u3089\u306a\u304f\u306a\u308b<\/td>\n<td>\u81ea\u52d5\u7d42\u4e86\uff08SQL\u30a8\u30f3\u30b8\u30f3\u5224\u65ad\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u8a66\u9a13\u3067\u72d9\u308f\u308c\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8<\/h3>\n<ul>\n<li><code>UNION ALL<\/code> \u3067\u3064\u306a\u3050\u5fc5\u8981\u304c\u3042\u308b\uff08<code>UNION<\/code>\u3060\u3068\u91cd\u8907\u6392\u9664\u3055\u308c\u8aa4\u52d5\u4f5c\uff09<\/li>\n<li>\u300c\u30a2\u30f3\u30ab\u30fc\u90e8\u304c1\u56de\u3060\u3051\u5b9f\u884c\u3055\u308c\u308b\u300d\u70b9<\/li>\n<li>\u300c\u7d42\u4e86\u6761\u4ef6\u300d\u304c\u6697\u9ed9\u7684\uff08= \u8fd4\u3059\u884c\u304c\u306a\u304f\u306a\u308b\uff09\u3067\u3042\u308b\u70b9<\/li>\n<li>\u5217\u306e\u6570\u30fb\u578b\u304c\u4e00\u81f4\u3057\u3066\u3044\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b<\/li>\n<\/ul>\n<h2>\u968e\u5c64\u306e\u6df1\u3055\u304c\u4e0d\u660e\u306a\u30c6\u30fc\u30d6\u30eb\u3068\u306f\uff1f\u518d\u5e30\u7684SQL\u304c\u5fc5\u8981\u306b\u306a\u308b\u5178\u578b\u69cb\u9020<\/h2>\n<p>\u518d\u5e30\u7684SQL\u304c\u771f\u4fa1\u3092\u767a\u63ee\u3059\u308b\u306e\u306f\u3001\u300c\u968e\u5c64\u306e\u6df1\u3055\u304c\u4e8b\u524d\u306b\u5206\u304b\u3089\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u300d\u3092\u6271\u3046\u3068\u304d\u3067\u3059\u3002\u3067\u306f\u3001\u305d\u3046\u3044\u3063\u305f\u69cb\u9020\u3068\u306f\u5177\u4f53\u7684\u306b\u3069\u3093\u306a\u3082\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<h3>\u25a0 \u4f8b\uff1a\u793e\u54e1\u30c6\u30fc\u30d6\u30eb\uff08\u81ea\u5df1\u53c2\u7167\uff09<\/h3>\n<pre><code>CREATE TABLE employees (\n    emp_id INT PRIMARY KEY,\n    name VARCHAR(50),\n    manager_id INT -- \u4e0a\u53f8\u306eemp_id\uff08NULL\u306a\u3089\u793e\u9577\uff09\n);<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>emp_id<\/th>\n<th>name<\/th>\n<th>manager_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u793e\u9577<\/td>\n<td>NULL<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u90e8\u9577A<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u8ab2\u9577A1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u30ea\u30fc\u30c0\u30fcA1<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u30e1\u30f3\u30d0\u30fcA1<\/td>\n<td>4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u306a\u305cJOIN\u3092\u4f7f\u3046\u767a\u60f3\u306b\u306a\u308b\u306e\u304b\uff1f<\/h3>\n<p>\u3053\u306e\u3088\u3046\u306a\u300c\u4e0a\u53f8\u3068\u90e8\u4e0b\u304c\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306b\u5165\u3063\u3066\u3044\u308b\u300d\u69cb\u9020\u3067\u306f\u3001<strong>\u81ea\u5206\u306e\u4e0a\u53f8\u3092\u77e5\u308b\u306b\u306f\u3001\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306e\u5225\u306e\u884c\u3068\u201c\u7d50\u5408\u201d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059<\/strong>\u3002\u3053\u306e\u3088\u3046\u306b\u3001\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u3092\u81ea\u5206\u81ea\u8eab\u3068\u7d50\u5408\u3059\u308b\u64cd\u4f5c\u3092\u300c\u81ea\u5df1\u7d50\u5408\uff08\u81ea\u5df1JOIN\uff09\u300d\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u305f\u3068\u3048\u3070\u300c\u5404\u793e\u54e1\u3068\u305d\u306e\u4e0a\u53f8\u30921\u884c\u3067\u51fa\u3057\u305f\u3044\u300d\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bJOIN\u3057\u307e\u3059\uff1a<\/p>\n<pre><code>SELECT\n  emp.name AS employee,\n  mgr.name AS manager\nFROM\n  employees emp\nLEFT JOIN employees mgr ON emp.manager_id = mgr.emp_id;<\/code><\/pre>\n<p>\u3055\u3089\u306b\u300c\u4e0a\u53f8\u306e\u4e0a\u53f8\u300d\u3084\u300c\u4e0a\u53f8\u306e\u4e0a\u53f8\u306e\u4e0a\u53f8\u300d\u307e\u3067\u8868\u793a\u3057\u305f\u3044\u3068\u304d\u306f\u3001JOIN\u3092\u4f55\u5ea6\u3082\u91cd\u306d\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff1a<\/p>\n<pre><code>SELECT\n  e1.name AS \u81ea\u5206,\n  e2.name AS \u4e0a\u53f8,\n  e3.name AS \u4e0a\u53f8\u306e\u4e0a\u53f8\nFROM\n  employees e1\nLEFT JOIN employees e2 ON e1.manager_id = e2.emp_id\nLEFT JOIN employees e3 ON e2.manager_id = e3.emp_id;<\/code><\/pre>\n<h3>\u25a0 \u306a\u305c\u5f93\u6765\u306eJOIN\u3067\u306f\u9650\u754c\u304c\u3042\u308b\u306e\u304b\uff1f<\/h3>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306aJOIN\u306f\u3001\u3042\u3089\u304b\u3058\u3081\u300c\u4f55\u968e\u5c64\u5fc5\u8981\u304b\u300d\u304c\u5206\u304b\u3063\u3066\u3044\u306a\u3051\u308c\u3070\u4f7f\u3048\u307e\u305b\u3093\u30025\u968e\u5c64\u308410\u968e\u5c64\u306b\u306a\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u306e\u306b\u3001JOIN\u3092\u4f55\u56de\u66f8\u3051\u3070\u3044\u3044\u304b\u4e8b\u524d\u306b\u5206\u304b\u3089\u306a\u3044\u2015\u2015\u3053\u308c\u304cJOIN\u306e\u9650\u754c\u3067\u3059\u3002<\/p>\n<h3>\u25a0 WITH RECURSIVE\u3067\u81ea\u52d5\u8d70\u67fb\uff01<\/h3>\n<pre><code>WITH RECURSIVE hierarchy AS (\n    SELECT emp_id, name, manager_id, 1 AS level\n    FROM employees\n    WHERE manager_id IS NULL\n\n    UNION ALL\n\n    SELECT e.emp_id, e.name, e.manager_id, h.level + 1\n    FROM employees e\n    JOIN hierarchy h ON e.manager_id = h.emp_id\n)\nSELECT * FROM hierarchy;<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b<code>WITH RECURSIVE<\/code>\u3092\u4f7f\u3048\u3070\u3001\u968e\u5c64\u304c\u5c3d\u304d\u308b\u307e\u3067\u81ea\u52d5\u3067\u7e70\u308a\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u51fa\u529b\u7d50\u679c\u306e\u30a4\u30e1\u30fc\u30b8<\/h3>\n<p>\u4e0a\u8a18\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u300c\u968e\u5c64\u30ec\u30d9\u30eb\u4ed8\u304d\u306e\u4e00\u89a7\u300d\u304c\u5f97\u3089\u308c\u307e\u3059\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>emp_id<\/th>\n<th>name<\/th>\n<th>manager_id<\/th>\n<th>level<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u793e\u9577<\/td>\n<td>NULL<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u90e8\u9577A<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u8ab2\u9577A1<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u30ea\u30fc\u30c0\u30fcA1<\/td>\n<td>3<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u30e1\u30f3\u30d0\u30fcA1<\/td>\n<td>4<\/td>\n<td>5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u968e\u5c64\u306e\u6df1\u3055\uff08level\u5217\uff09<\/strong>\u304c\u3042\u308b\u3053\u3068\u3067\u3001\u300c\u3069\u306e\u793e\u54e1\u304c\u3069\u306e\u968e\u5c64\u306b\u3044\u308b\u304b\u300d\u304c\u4e00\u76ee\u3067\u5206\u304b\u308b\u306e\u3082\u3001\u518d\u5e30SQL\u306e\u30e1\u30ea\u30c3\u30c8\u3067\u3059\u3002<\/p>\n<h3>\u25a0 \u3053\u3046\u3057\u305f\u69cb\u9020\u306f\u8a66\u9a13\u3067\u3082\u983b\u51fa\uff01<\/h3>\n<p>IPA\u306e\u5fdc\u7528\u60c5\u5831\u306a\u3069\u3067\u306f\u3001\u3053\u306e\u3088\u3046\u306a\u300c\u81ea\u5df1\u53c2\u7167\u306e\u968e\u5c64\u69cb\u9020\u30c6\u30fc\u30d6\u30eb\u300d\u304c\u7e70\u308a\u8fd4\u3057\u767b\u5834\u3057\u307e\u3059\u3002\u6b63\u78ba\u306b\u7406\u89e3\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u306a\u305c\u968e\u5c64\u69cb\u9020\u3092SQL\u3067\u53d6\u5f97\u3059\u308b\u306e\u304b\uff1f\u518d\u5e30\u7684SQL\u304c\u6c42\u3081\u3089\u308c\u308b\u5b9f\u52d9\u3068\u8a66\u9a13\u306e\u7406\u7531<\/h2>\n<p>\u305d\u3082\u305d\u3082\u300c\u968e\u5c64\u69cb\u9020\u3092SQL\u3067\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u304b\uff1f\u300d\u3068\u3044\u3046\u7d20\u6734\u306a\u7591\u554f\u306f\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002\u5b9f\u52d9\u3067\u3082\u8a66\u9a13\u3067\u3082\u3001\u3053\u306e\u80fd\u529b\u304c\u6c42\u3081\u3089\u308c\u308b\u7406\u7531\u3092\u6574\u7406\u3057\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u5b9f\u52d9\u3067\u306e\u5fc5\u8981\u6027<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u30b7\u30fc\u30f3<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7d44\u7e54\u56f3<\/td>\n<td>\u793e\u9577\u304b\u3089\u672b\u7aef\u793e\u54e1\u307e\u3067\u306e\u968e\u5c64\u3092\u305f\u3069\u308a\u305f\u3044<\/td>\n<\/tr>\n<tr>\n<td>\u30ab\u30c6\u30b4\u30ea\u7ba1\u7406<\/td>\n<td>EC\u30b5\u30a4\u30c8\u306e\u300c\u30ab\u30c6\u30b4\u30ea\u2192\u30b5\u30d6\u30ab\u30c6\u30b4\u30ea\u2192\u5546\u54c1\u300d\u69cb\u9020<\/td>\n<\/tr>\n<tr>\n<td>\u30d5\u30a1\u30a4\u30eb\u69cb\u9020<\/td>\n<td>\u30d5\u30a9\u30eb\u30c0\u2192\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u2192\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u89a7\u53d6\u5f97<\/td>\n<\/tr>\n<tr>\n<td>\u30ca\u30d3\u8868\u793a<\/td>\n<td>\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306a\u3069\u3001\u4e0a\u4f4d\u304b\u3089\u4e0b\u4f4d\u3078\u69cb\u9020\u3092\u8868\u793a\u3057\u305f\u3044<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u8a66\u9a13\u3067\u306e\u5fc5\u8981\u6027\uff08\u5348\u5f8c\u554f\u984c\uff09<\/h3>\n<ul>\n<li>\u300c\u89aa\u2192\u5b50\u2192\u5b6b\u30ce\u30fc\u30c9\u3092\u8fbf\u308b\u30ed\u30b8\u30c3\u30af\u300d\u3092SQL\u3067\u6b63\u78ba\u306b\u66f8\u3051\u308b\u304b<\/li>\n<li>\u300cID\uff0f\u89aaID\u300d\u5f62\u5f0f\u306e\u8868\u3092\u8aad\u307f\u53d6\u308a\u3001\u518d\u5e30\u69cb\u9020\u3068\u8a8d\u8b58\u3067\u304d\u308b\u304b<\/li>\n<li>\u300c\u69cb\u9020\u3092\u305f\u3069\u308b\u51e6\u7406\u306e\u6d41\u308c\u300d\u3092\u65e5\u672c\u8a9e\u3067\u8aac\u660e\u3067\u304d\u308b\u304b<\/li>\n<\/ul>\n<h3>\u25a0 \u518d\u5e30\u7684SQL\u306e\u4fa1\u5024<\/h3>\n<p>\u5358\u306bSQL\u306e\u6587\u6cd5\u3092\u899a\u3048\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u300c\u30c4\u30ea\u30fc\u69cb\u9020\u306e\u8d70\u67fb\u65b9\u6cd5\u300d\u300c\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u306e\u7406\u89e3\u300d\u300c\u968e\u5c64\u306e\u5168\u4f53\u50cf\u3092\u51fa\u529b\u3059\u308b\u529b\u300d\u306a\u3069\u3001<strong>\u69cb\u9020\u7684\u306a\u8003\u3048\u65b9\u3092\u8eab\u306b\u3064\u3051\u308b\u8a13\u7df4<\/strong>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u518d\u5e30\u7684SQL\u3092\u4f7f\u3046\u3079\u304d\uff0f\u907f\u3051\u308b\u3079\u304d\u30b1\u30fc\u30b9\u2502\u8a66\u9a13\u5bfe\u7b56\u3067\u306e\u5224\u65ad\u57fa\u6e96<\/h2>\n<p>\u518d\u5e30\u7684SQL\u306f\u975e\u5e38\u306b\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u304c\u3001\u300c\u3069\u3093\u306a\u3068\u304d\u3067\u3082\u4f7f\u3046\u3079\u304d\u300d\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u8a66\u9a13\u3067\u306f\u300c\u3053\u308c\u306f\u518d\u5e30SQL\u3067\u89e3\u304f\u3079\u304d\u304b\uff1f\u300d\u3068\u3044\u3046\u5224\u65ad\u304c\u554f\u308f\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u300c\u518d\u5e30\u3092\u4f7f\u3046\uff0f\u4f7f\u308f\u306a\u3044\u300d\u5224\u65ad\u57fa\u6e96\u3092\u5b9f\u4f8b\u30d9\u30fc\u30b9\u3067\u6574\u7406\u3057\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u518d\u5e30\u7684SQL\u304c\u9069\u3057\u3066\u3044\u308b\u30b1\u30fc\u30b9<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f3<\/th>\n<th>\u5185\u5bb9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u968e\u5c64\u69cb\u9020\u306e\u63a2\u7d22<\/strong><\/td>\n<td>\u4e0a\u53f8\u2015\u90e8\u4e0b\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u9020\u3001\u89aa\u30ab\u30c6\u30b4\u30ea\u2015\u5b50\u30ab\u30c6\u30b4\u30ea \u306a\u3069<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30c4\u30ea\u30fc\u69cb\u9020\u306e\u51fa\u529b<\/strong><\/td>\n<td>\u30ce\u30fc\u30c9\u304b\u3089\u5168\u3066\u306e\u5b50\u30ce\u30fc\u30c9\u3092\u4e00\u89a7\u306b\u3059\u308b\u5834\u5408<\/td>\n<\/tr>\n<tr>\n<td><strong>\u7d42\u7aef\u307e\u3067\u5230\u9054\u3059\u308b\u30eb\u30fc\u30c8\u3092\u5217\u6319\u3057\u305f\u3044<\/strong><\/td>\n<td>\u305f\u3068\u3048\u3070\u300cA\u2192B\u2192C\u2192D\u300d\u3068\u3044\u3046\u7d4c\u8def\u30921\u884c\u305a\u3064\u78ba\u8a8d\u3057\u305f\u3044\u3068\u304d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u518d\u5e30\u7684SQL\u3092\u907f\u3051\u308b\u3079\u304d\u30b1\u30fc\u30b9<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f3<\/th>\n<th>\u7406\u7531<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u968e\u5c64\u304c\u6df1\u3059\u304e\u308b or \u30c7\u30fc\u30bf\u91cf\u304c\u975e\u5e38\u306b\u591a\u3044<\/strong><\/td>\n<td>\u51e6\u7406\u6642\u9593\u304c\u9577\u304f\u306a\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u5f71\u97ff<\/td>\n<\/tr>\n<tr>\n<td><strong>\u968e\u5c64\u69cb\u9020\u304c\u4e0d\u8981\u306a\u96c6\u8a08\u30fbJOIN<\/strong><\/td>\n<td>\u5358\u7d14\u306a\u7d50\u5408\u3084\u96c6\u8a08\u3067\u6e08\u3080\u306a\u3089\u3001\u518d\u5e30\u306f\u904e\u5270\u8a2d\u8a08<\/td>\n<\/tr>\n<tr>\n<td><strong>\u7d42\u4e86\u6761\u4ef6\u304c\u4e0d\u660e\u78ba or \u30eb\u30fc\u30d7\u3057\u305d\u3046\u306a\u30c7\u30fc\u30bf<\/strong><\/td>\n<td>\u7121\u9650\u30eb\u30fc\u30d7\u306e\u5371\u967a\u304c\u3042\u308b\uff08\u30c6\u30b9\u30c8\u306b\u3042\u308a\u304c\u3061\u306a\u30c8\u30e9\u30c3\u30d7\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u8a66\u9a13\u3067\u306e\u300c\u5224\u65ad\u306e\u30b3\u30c4\u300d<\/h3>\n<ul>\n<li>\u554f\u984c\u6587\u306b\u300c\u968e\u5c64\u300d\u300c\u69cb\u9020\u300d\u300c\u7e70\u308a\u8fd4\u3057\u300d\u300c\u89aa\u5b50\u95a2\u4fc2\u300d\u300c\u3059\u3079\u3066\u306e\u95a2\u9023\u8981\u7d20\u3092\u5217\u6319\u300d\u3068\u3044\u3063\u305f\u30ad\u30fc\u30ef\u30fc\u30c9\u304c\u3042\u308c\u3070\u3001\u518d\u5e30SQL\u306e\u53ef\u80fd\u6027\u304c\u9ad8\u3044<\/li>\n<li>\u8868\u5f62\u5f0f\u3067\u300cID\uff0f\u89aaID\u300d\u306e\u5f62\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u304d\u306f\u30c4\u30ea\u30fc\u69cb\u9020\u3092\u60f3\u5b9a\u3059\u308b<\/li>\n<li>\u300c\u518d\u5e30\u3092\u4f7f\u308f\u306a\u3044\u3068\u89e3\u3051\u306a\u3044\u300d\u554f\u984c\u306f\u9650\u3089\u308c\u3066\u304a\u308a\u3001\u591a\u304f\u306f\u300c\u518d\u5e30\u3067\u3082\u89e3\u3051\u308b\u304c\u3001\u975e\u518d\u5e30\u3067\u3082\u53ef\u300d\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b<\/li>\n<\/ul>\n<h3>\u25a0 \u8a66\u9a13\u3067\u306e\u201c\u7f60\u201d\u306b\u6ce8\u610f\uff01<\/h3>\n<ul>\n<li><code>UNION<\/code>\u3068<code>UNION ALL<\/code>\u306e\u9055\u3044\u3092\u554f\u3046\u9078\u629e\u80a2<\/li>\n<li>\u518d\u5e30\u90e8\u3067\u7d50\u5408\u6761\u4ef6\u3092\u30df\u30b9\u3089\u305b\u308b\u30d1\u30bf\u30fc\u30f3<\/li>\n<li>\u7d42\u4e86\u6761\u4ef6\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u2192\u7121\u9650\u518d\u5e30\u306b\u306a\u308b\u30b1\u30fc\u30b9<\/li>\n<li>\u5217\u306e\u6570\u304c\u63c3\u3063\u3066\u3044\u306a\u3044\u30a8\u30e9\u30fc\uff08\u30d2\u30f3\u30c8\u306b\u6ce8\u76ee\uff09<\/li>\n<\/ul>\n<h2>\u8a66\u9a13\u3067\u72d9\u308f\u308c\u3084\u3059\u3044\u518d\u5e30\u7684SQL\u306e\u3072\u3063\u304b\u3051\u30d1\u30bf\u30fc\u30f3\u3068\u89e3\u304d\u65b9\u306e\u30b3\u30c4<\/h2>\n<p>\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u5348\u5f8c\u554f\u984c\u3067\u306f\u3001\u300cSQL\u306e\u69cb\u6587\u305d\u306e\u3082\u306e\u300d\u3088\u308a\u3082\u3001\u300c\u8aad\u307f\u9055\u3044\u300d\u3084\u300c\u5224\u65ad\u30df\u30b9\u300d\u3092\u8a98\u3046\u3088\u3046\u306a\u3072\u3063\u304b\u3051\u65b9\u304c\u3088\u304f\u898b\u3089\u308c\u307e\u3059\u3002\u518d\u5e30\u7684SQL\u306b\u95a2\u3057\u3066\u3082\u3001\u5178\u578b\u7684\u306a\u30d1\u30bf\u30fc\u30f3\u304c\u3044\u304f\u3064\u304b\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u3088\u304f\u3042\u308b\u3072\u3063\u304b\u3051\u30d1\u30bf\u30fc\u30f3<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u30d1\u30bf\u30fc\u30f3<\/th>\n<th>\u89e3\u8aac<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>UNION\u3092\u4f7f\u308f\u305b\u308b\u9078\u629e\u80a2<\/strong><\/td>\n<td><code>UNION ALL<\/code>\u3067\u306a\u3051\u308c\u3070\u518d\u5e30\u51e6\u7406\u306f\u9014\u4e2d\u3067\u6b62\u307e\u308b\uff08\u91cd\u8907\u304c\u6d88\u3048\u308b\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u518d\u5e30\u90e8\u306eJOIN\u6761\u4ef6\u306b\u30df\u30b9\u304c\u3042\u308b<\/strong><\/td>\n<td>\u89aa\u5b50\u95a2\u4fc2\u306e\u7d50\u3073\u65b9\u304c\u9006\u306b\u306a\u3063\u3066\u3044\u308b\u306a\u3069\u3001\u7d50\u679c\u304c\u7a7a\u306b\u306a\u308b<\/td>\n<\/tr>\n<tr>\n<td><strong>\u7d42\u4e86\u6761\u4ef6\u304c\u66d6\u6627<\/strong><\/td>\n<td>WHERE\u53e5\u304c\u306a\u304f\u30eb\u30fc\u30d7\u3057\u7d9a\u3051\u308b\u5371\u967a\u3001\u7279\u306b<code>LEVEL<\/code>\u306a\u3069\u306e\u5236\u5fa1\u304c\u306a\u3044\u5834\u5408<\/td>\n<\/tr>\n<tr>\n<td><strong>\u5217\u6570\u30fb\u578b\u304c\u4e00\u81f4\u3057\u306a\u3044<\/strong><\/td>\n<td>\u30a2\u30f3\u30ab\u30fc\u90e8\u3068\u518d\u5e30\u90e8\u306eSELECT\u53e5\u3067\u5217\u306e\u6570\u304c\u305a\u308c\u308b\u3068\u5373\u30a8\u30e9\u30fc<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u25a0 \u30b3\u30c41\uff1a\u30a2\u30f3\u30ab\u30fc\u3068\u518d\u5e30\u90e8\u306e\u300c\u5217\u540d\u30fb\u9806\u5e8f\u30fb\u578b\u300d\u3092\u78ba\u8a8d<\/h3>\n<p>\u5348\u5f8c\u554f\u984c\u3067\u306fSQL\u6587\u306e\u4e00\u90e8\u3060\u3051\u304c\u4e0e\u3048\u3089\u308c\u3001\u6b8b\u308a\u3092\u9078\u629e\u80a2\u304b\u3089\u9078\u3076\u5f62\u5f0f\u3082\u591a\u3044\u3067\u3059\u3002\u3053\u306e\u3068\u304d\u3001\u6700\u3082\u91cd\u8981\u306a\u306e\u304c\u300c\u5217\u306e\u4e00\u81f4\u300d\u3067\u3059\u3002<\/p>\n<p>&#x2705; <strong>\u30a2\u30f3\u30ab\u30fc\u3068\u518d\u5e30\u90e8\u306eSELECT\u6587\u3067\u3001\u5217\u6570\u30fb\u9806\u756a\u30fb\u30c7\u30fc\u30bf\u578b\u304c\u540c\u3058\u306b\u306a\u3063\u3066\u3044\u308b\u304b\uff1f<\/strong><br \/>\n\u2192 \u3053\u308c\u304c\u4e00\u81f4\u3057\u3066\u3044\u306a\u3044\u3068\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308b\u304b\u3001\u7d50\u679c\u304c\u51fa\u306a\u3044\u30b1\u30fc\u30b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u30b3\u30c42\uff1a\u51e6\u7406\u306e\u6d41\u308c\u3092\u64ec\u4f3c\u30b3\u30fc\u30c9\u7684\u306b\u66f8\u3044\u3066\u307f\u308b<\/h3>\n<pre><code>-- \u4f8b\uff1a\n1. \u6700\u521d\u306b\u300c\u89aaID\u304cNULL\u300d\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\n2. \u305d\u306eID\u3092\u4f7f\u3063\u3066\u300c\u5b50ID = \u89aaID\u300d\u306eJOIN\u3092\u7e70\u308a\u8fd4\u3059\n3. \u7d42\u4e86\u6761\u4ef6\u306f\u3001JOIN\u3067\u30de\u30c3\u30c1\u3057\u306a\u304f\u306a\u3063\u305f\u3068\u304d\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u554f\u984c\u6587\u3092SQL\u3060\u3051\u3067\u306a\u304f\u300c\u65e5\u672c\u8a9e\u306e\u51e6\u7406\u624b\u9806\u300d\u306b\u8a00\u3044\u63db\u3048\u3066\u307f\u308b\u3068\u3001\u898b\u843d\u3068\u3057\u304c\u6e1b\u308a\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u30b3\u30c43\uff1a\u300c1\u56de\u76ee\u3060\u3051\u5b9f\u884c\u3055\u308c\u308b\u90e8\u5206\u300d\u304c\u3069\u3053\u304b\u3092\u898b\u6975\u3081\u308b<\/h3>\n<p>\u30a2\u30f3\u30ab\u30fc\u90e8\u306f1\u56de\u3057\u304b\u5b9f\u884c\u3055\u308c\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001<strong>\u305d\u3053\u306bWHERE\u53e5\u3084LIMIT\u53e5\u304c\u3042\u308b\u3068\u3001\u305d\u306e\u5f8c\u306e\u518d\u5e30\u51e6\u7406\u306b\u76f4\u63a5\u5f71\u97ff\u3092\u4e0e\u3048\u308b<\/strong>\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u25a0 \u8a66\u9a13\u30c6\u30af\u30cb\u30c3\u30af\uff1a\u8ff7\u3063\u305f\u3089\u30a2\u30f3\u30ab\u30fc\u2192\u518d\u5e30\u2192\u6700\u7d42SELECT\u306e\u9806\u306b\u78ba\u8a8d<\/h3>\n<ol>\n<li><strong>\u30a2\u30f3\u30ab\u30fc\u90e8<\/strong>\uff1a\u3069\u3053\u304b\u3089\u59cb\u307e\u3063\u3066\u3044\u308b\uff1f<\/li>\n<li><strong>\u518d\u5e30\u90e8<\/strong>\uff1a\u4f55\u3092JOIN\u3057\u3066\u3044\u308b\uff1f<\/li>\n<li><strong>\u6700\u7d42SELECT<\/strong>\uff1a\u4f55\u3092\u51fa\u529b\u3057\u3066\u3044\u308b\uff1f<\/li>\n<\/ol>\n<h2>\u518d\u5e30\u7684SQL\u306e\u7406\u89e3\u307e\u3068\u3081\u2502WITH RECURSIVE\u53e5\u3067\u968e\u5c64\u30c7\u30fc\u30bf\u3092\u5236\u3059<\/h2>\n<p>\u518d\u5e30\u7684SQL\u306f\u3001\u300c\u968e\u5c64\u69cb\u9020\u300d\u300c\u30c4\u30ea\u30fc\u69cb\u9020\u300d\u3068\u3044\u3063\u305f\u30c7\u30fc\u30bf\u306b\u5f37\u304f\u3001<code>WITH RECURSIVE<\/code>\u53e5\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u5f93\u6765\u306eSQL\u3067\u306f\u96e3\u3057\u304b\u3063\u305f\u51e6\u7406\u3082\u7c21\u6f54\u306b\u8868\u73fe\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5f37\u529b\u306a\u4e00\u65b9\u3067\u3001<strong>\u66f8\u304d\u65b9\u306e\u30eb\u30fc\u30eb\u3084\u4f7f\u3044\u3069\u3053\u308d\u3092\u8aa4\u308b\u3068\u7d50\u679c\u304c\u5f97\u3089\u308c\u306a\u3044<\/strong>\u3001\u3042\u308b\u3044\u306f<strong>\u7121\u9650\u30eb\u30fc\u30d7\u3084\u30a8\u30e9\u30fc<\/strong>\u306e\u539f\u56e0\u306b\u3082\u306a\u308a\u5f97\u307e\u3059\u3002<\/p>\n<p>\u5348\u5f8c\u8a66\u9a13\u3067\u306f\u300cSQL\u306e\u6b63\u78ba\u306a\u69cb\u6587\u77e5\u8b58\u300d\u306b\u52a0\u3048\u3001\u300c\u51e6\u7406\u306e\u6d41\u308c\u3092\u8ffd\u3046\u529b\u300d\u300c\u6587\u8108\u304b\u3089\u518d\u5e30\u304c\u5fc5\u8981\u304b\u3092\u5224\u65ad\u3059\u308b\u529b\u300d\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30dd\u30a4\u30f3\u30c8\u3092\u610f\u8b58\u3057\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h3>\u25a0 \u518d\u5e30SQL\u306e\u653b\u7565\u30dd\u30a4\u30f3\u30c8\u307e\u3068\u3081<\/h3>\n<ul>\n<li><code>WITH RECURSIVE<\/code>\u306f\u300c\u30a2\u30f3\u30ab\u30fc\u90e8\uff0b\u518d\u5e30\u90e8\u300d\u306e2\u6bb5\u69cb\u6210<\/li>\n<li>\u5fc5\u305a<code>UNION ALL<\/code>\u3092\u4f7f\u3044\u3001\u5217\u6570\u3068\u578b\u3092\u5408\u308f\u305b\u308b<\/li>\n<li>\u30a2\u30f3\u30ab\u30fc\u90e8\u306f1\u56de\u3001\u518d\u5e30\u90e8\u306f\u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u3055\u308c\u308b<\/li>\n<li>\u518d\u5e30\u304c\u5fc5\u8981\u306a\u69cb\u9020\u304b\u3069\u3046\u304b\u306f\u300cID\uff0f\u89aaID\u300d\u578b\u306e\u8868\u3092\u30c1\u30a7\u30c3\u30af<\/li>\n<li>\u7d42\u4e86\u6761\u4ef6\u3084JOIN\u6761\u4ef6\u306b\u4e0d\u5099\u304c\u3042\u308b\u3068\u610f\u56f3\u901a\u308a\u306b\u52d5\u304b\u306a\u3044<\/li>\n<li>SQL\u5168\u4f53\u3092\u300c\u624b\u9806\u300d\u3084\u300c\u6d41\u308c\u300d\u3067\u7406\u89e3\u3059\u308b\u3068\u30df\u30b9\u304c\u6e1b\u308b<\/li>\n<\/ul>\n<p>\u5b9f\u52d9\u3067\u3082\u518d\u5e30\u7684SQL\u306f\u30c7\u30fc\u30bf\u5206\u6790\u3084\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u3067\u91cd\u5b9d\u3055\u308c\u308b\u30b9\u30ad\u30eb\u3067\u3059\u3002\u5fdc\u7528\u60c5\u5831\u306e\u5408\u683c\u3092\u76ee\u6307\u3059\u3068\u540c\u6642\u306b\u3001\u73fe\u5834\u3067\u3082\u901a\u7528\u3059\u308b\u529b\u3092\u3053\u306e\u6a5f\u4f1a\u306b\u305c\u3072\u990a\u3044\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u306b\u306f\u3055\u307e\u3056\u307e\u306a\u69cb\u6587\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u300c\u518d\u5e30\u7684SQL\u300d\u306f\u4e00\u6b69\u9032\u3093\u3060\u7406\u89e3\u304c\u6c42\u3081\u3089\u308c\u308b\u9818\u57df\u3067\u3059\u3002\u7279\u306b\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306a\u3069\u306e\u5348\u5f8c\u8a66\u9a13\u3067\u306f\u3001\u30c4\u30ea\u30fc\u69cb\u9020\u3084\u968e\u5c64\u69cb\u9020\u306e\u30c7\u30fc\u30bf\u64cd\u4f5c\u306b\u95a2\u9023\u3057\u3066\u3001WITH RECURS &#8230; <\/p>\n","protected":false},"author":2,"featured_media":5469,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","columnck":"","stmeta_robots":"index, follow","st_titlewords":"","st_title_extra":"","st_keywords":"","st_description":"","st_display_ad_mark":"","st_display_ad_mark_hide":"","textcopyck":"","st_copyright":"","st_copyurl":"","eyecatch_set":"","st_youtube_url":"","st_youtube_eyecatch":"","headerwidget_set":"","updatewidget_set":"","kanrenwidget_set":"","ikkatuwidget_set":"","koukoku_set":"","auto_adsense_koukoku_set":"","st_redirect":"","st_redirect_url_as_canonical":"","st_redirect_pvm_do_not_track":"","post_data_updatewidget_set":"","st_post_header_under_bg":"","st_twitter_tag":"","affinger_note":"","rankdisplayck":"","st_head_code":"","st_footer_code":"","st_post_header_under_code":"","_st_toc_override":false,"_st_toc_settings":[]},"categories":[3],"tags":[6],"class_list":["post-5450","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ipa","tag-6"],"_links":{"self":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/5450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/comments?post=5450"}],"version-history":[{"count":0,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/5450\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/media\/5469"}],"wp:attachment":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/media?parent=5450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/categories?post=5450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/tags?post=5450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}