{"id":14618,"date":"2021-09-26T13:58:26","date_gmt":"2021-09-26T04:58:26","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=14618"},"modified":"2023-05-27T23:15:33","modified_gmt":"2023-05-27T14:15:33","slug":"%e3%80%90sql%e3%80%91%e3%80%8cjoin%e3%80%8d%e3%81%a8%e3%80%8c%e3%83%91%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%b3%e3%82%b9%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=14618","title":{"rendered":"\u3010SQL\u3011\u300cJOIN\u300d\u3068\u300c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<p>JOIN\u304c\u5897\u3048\u308b\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3057\u307e\u3059\u3002<\/p>\n<p>INNER JOIN\u306e\u5834\u5408\u306f\u8ad6\u7406\u548c\u306b\u306a\u308b\u306e\u3067\u3001A\u3001B\u3001C\u3001D\u30684\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u3063\u305f\u5834\u5408\u306f\u3001A\u3068B\u3001A\u3068C\u3001A\u3068D\u3001B\u3068C\u3001B\u3068D\u3001C\u3068D\u3068\u3044\u3046\u3088\u3046\u306b\u91cd\u306a\u308a\u3092\u8abf\u3079\u3066\u3044\u304f\u306e\u3067\u6307\u6570\u95a2\u6570\u7684\u306b\u5897\u52a0\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>JOIN\u306e\u30c6\u30fc\u30d6\u30eb\u30b9\u30ad\u30e3\u30f3\u306f\u639b\u3051\u7b97\u306a\u306e\u3067\u300110\u884c\u306810\u884c\u306a\u3089100\u884c\u30011000\u884c\u30681000\u884c\u306a\u30891000000\u884c\u306e\u30b9\u30ad\u30e3\u30f3\u304c\u8d70\u308a\u307e\u3059\u3002<\/p>\n<h2>\u3058\u3083\u3042\u3001JOIN\u3092\u4f7f\u3063\u3066\u306f\u3044\u3051\u306a\u3044\u306e\u304b\uff1f<\/h2>\n<p>\u305d\u308c\u306f\u306a\u3044\u3067\u3059\u3002N+1\u554f\u984c\u306e\u6e29\u5e8a\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u4f7f\u308f\u306a\u3044\u3068\u3044\u3046\u9078\u629e\u80a2\u306f\u306a\u3044\u3067\u3059\u3002<\/p>\n<h2>\u5bfe\u7b56<\/h2>\n<h3>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8cbc\u308b\u3002<\/h3>\n<p>100\u884c\u3068100\u884c\u306e\u30b9\u30ad\u30e3\u30f3\u306e\u5834\u5408\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u8cbc\u3089\u308c\u3066\u306a\u304b\u3063\u305f\u3089100\u2716\ufe0f100\u306e10000\u884c\u306e\u30b9\u30ad\u30e3\u30f3\u304c\u8d70\u308a\u307e\u3059\u304c\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u8cbc\u308c\u3066\u3044\u305f\u3089\u3001100+100\u306e200\u884c\u306e\u30b9\u30ad\u30e3\u30f3\u3067\u6e08\u307f\u307e\u3059\u3002<\/p>\n<h3>SQL\u3092\u898b\u76f4\u3059\u3002<\/h3>\n<h4>JOIN\u306e\u56de\u6570\u3092\u6e1b\u3089\u3059\u3053\u3068\u3002<\/h4>\n<p>\u305d\u3082\u305d\u3082\u3001\u4e0d\u8981\u306aJOIN\u3092\u3057\u3066\u3044\u306a\u3044\u304b\u898b\u76f4\u3059\u3002<\/p>\n<h4>WHERE\u53e5\u306e\u524d\u306bON\u53e5\u3067\u3067\u304d\u308b\u3060\u3051\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u3002<\/h4>\n<p>ON\u53e5\u3067\u4e8b\u524d\u306b\u7d5e\u308a\u8fbc\u3081\u308b\u306e\u3067\u3042\u308c\u3070\u3001JOIN\u5143\u3084JOIN\u5148\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u884c\u6570\u304c\u5c11\u306a\u304f\u306a\u3063\u3066\u3044\u308b\u307b\u3069JOIN\u3057\u305f\u969b\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306f\u5411\u4e0a\u3057\u307e\u3059\u3002\u4f55\u306a\u3089WHERE\u53e5\u3067\u4f7f\u3063\u3066\u3044\u308b\u6761\u4ef6\u306f\u5168\u3066\u30b5\u30d6\u30af\u30a8\u30ea\u306b\u6301\u3063\u3066\u3044\u304d\u3001JOIN\u5143\u3084JOIN\u5148\u306e\u884c\u6570\u3092\u6e1b\u3089\u3059\u3053\u3068\u306b\u6d3b\u7528\u3059\u308b\u3053\u3068\u304c\u61f8\u547d\u3067\u3059\u3002\u306a\u304a\u3001<span style=\"color: #ff0000;\"><strong>ON\u53e5\u306f\u7d50\u5408\u6761\u4ef6\u306e\u307f\u306b\u4f7f\u3046\u3068\u601d\u308f\u308c\u3066\u3044\u308b\u65b9\u3082\u591a\u3044\u306e\u3067\u3059\u304c\u3001\u666e\u901a\u306b\u6761\u4ef6\u306e\u7d5e\u308a\u8fbc\u307f\u306b\u3082\u4f7f\u3048\u308b<\/strong><\/span>\u306e\u3067\u305d\u308c\u304cSQL\u306e\u826f\u3044\u5b9f\u88c5\u65b9\u6cd5\u306b\u3082\u306a\u308a\u307e\u3059\u306e\u3067\u899a\u3048\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"HudYEyHujZ\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=14748\">\u3010SQL\u3011\u300cON\u53e5\u300d\u306e\u610f\u5916\u3068\u77e5\u3089\u306a\u3044\u6d3b\u7528\u6cd5<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=14748&#038;embed=true#?secret=HudYEyHujZ\" data-secret=\"HudYEyHujZ\" width=\"500\" height=\"282\" title=\"&#8220;\u3010SQL\u3011\u300cON\u53e5\u300d\u306e\u610f\u5916\u3068\u77e5\u3089\u306a\u3044\u6d3b\u7528\u6cd5&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>Oracle\u3068MySQL\u304c\u3089\u307f\u306e\u30ed\u30c3\u30af\u554f\u984c\u306f\u7406\u89e3\u3057\u3066\u304a\u304f<\/h3>\n<p>Oracle\u3068MySQL\u3067\u306f\u300c\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u3092JOIN\u3057\u3066\u305d\u306e\u3046\u3061\u306e\u4e00\u3064\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u51e6\u7406\u3092\u884c\u3046\u5834\u5408MySQL\u306e\u65b9\u304cOracle\u3088\u308a\u30ed\u30c3\u30af\u306e\u7bc4\u56f2\u304c\u5e83\u3044\u300d\u3068\u3044\u3046\u554f\u984c\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>Oracle\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306bJOIN\u3059\u308bSQL\u306eFOR UPDATE\u306e\u5f8c\u308d\u306b\u300c\u30c6\u30fc\u30d6\u30eb\u540d.\u30ab\u30e9\u30e0\u540d\u300d\u3068\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u30ed\u30c3\u30af\u306e\u7bc4\u56f2\u3092\u72ed\u304f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001MySQL\u3060\u3068\u3067\u304d\u306a\u3044\u306e\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">SELECT * FROM \u30c6\u30fc\u30d6\u30eb1\r\nINNER JOIN \u30c6\u30fc\u30d6\u30eb2\r\nON \u30c6\u30fc\u30d6\u30eb1.\u30ab\u30e9\u30e01 = \u30c6\u30fc\u30d6\u30eb2.\u30ab\u30e9\u30e01\r\nwhere \u30c6\u30fc\u30d6\u30eb1.\u30ab\u30e9\u30e01 = ?\r\nFOR UPDATE<\/pre>\n<p>\u306a\u306e\u3067MySQL\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b5\u30d6\u30af\u30a8\u30ea\u306b\u3088\u308b\u5bfe\u51e6\u3092\u53d6\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">SELECT * FROM\r\n(SELECT * FROM \u30c6\u30fc\u30d6\u30eb1 where \u30ab\u30e9\u30e01 = ? FOR UPDATE) a\r\nINNER JOIN \u30c6\u30fc\u30d6\u30eb2\r\nON \u30c6\u30fc\u30d6\u30eb1.\u30ab\u30e9\u30e01 = \u30c6\u30fc\u30d6\u30eb2.\u30ab\u30e9\u30e01<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067MySQL\u3067\u3082FOR UPDATE\u306e\u7bc4\u56f2\u304c\u30c6\u30fc\u30d6\u30eb1\u3060\u3051\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u7279\u306b\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u52a3\u5316\u3059\u308b\u3053\u3068\u306a\u304f\u30ed\u30c3\u30af\u306e\u7bc4\u56f2\u3092\u9650\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"JOIN\u304c\u5897\u3048\u308b\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3057\u307e\u3059\u3002 INNER JOIN\u306e\u5834\u5408\u306f\u8ad6\u7406\u548c\u306b\u306a\u308b\u306e\u3067\u3001A\u3001B\u3001C\u3001D\u30684\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u3063\u305f\u5834\u5408\u306f\u3001A\u3068B\u3001A\u3068C\u3001A\u3068D\u3001B\u3068C\u3001B\u3068D\u3001C\u3068D\u3068\u3044\u3046\u3088\u3046\u306b\u91cd\u306a\u308a\u3092\u8abf\u3079\u3066\u3044\u304f\u306e\u3067 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/14618"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14618"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/14618\/revisions"}],"predecessor-version":[{"id":20585,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/14618\/revisions\/20585"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14618"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}