{"id":4727,"date":"2018-06-21T03:48:56","date_gmt":"2018-06-20T18:48:56","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=4727"},"modified":"2023-05-27T23:19:32","modified_gmt":"2023-05-27T14:19:32","slug":"%e3%80%90sql%e3%80%91%ef%bc%92%e3%81%a4%e3%81%ae%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e9%96%93%e3%81%a7%e5%80%a4%e3%81%8c%e4%b8%80%e8%87%b4%e3%81%99%e3%82%8b%e3%83%87%e3%83%bc%e3%82%bf%e3%81%ae","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=4727","title":{"rendered":"\u3010SQL\u3011\uff12\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u9593\u3067\u5024\u304c\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u306e\u307f\u62bd\u51fa\u3059\u308b\u3002(IN\u3068EXISTS)"},"content":{"rendered":"<h2>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf<\/h2>\n<h3>USER_MASTER<\/h3>\n<table width=\"236\">\n<tbody>\n<tr>\n<th width=\"72\">USER_ID<\/th>\n<th width=\"72\">DEPT_NO<\/th>\n<th width=\"92\">USER_NAME<\/th>\n<\/tr>\n<tr>\n<td>0021<\/td>\n<td>1002<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u5b50<\/td>\n<\/tr>\n<tr>\n<td>0022<\/td>\n<td>1003<\/td>\n<td>\u5c0f\u6cc9 \u4e09\u90ce<\/td>\n<\/tr>\n<tr>\n<td>0023<\/td>\n<td>1004<\/td>\n<td>\u5c0f\u6cc9 \u82b1\u5b50<\/td>\n<\/tr>\n<tr>\n<td>0020<\/td>\n<td>1001<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u4e00<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>AUTHORIZATION<\/h3>\n<table style=\"border-collapse: collapse; width: 162pt;\" border=\"0\" width=\"216\" cellspacing=\"0\" cellpadding=\"0\">\n<colgroup>\n<col style=\"width: 54pt;\" span=\"3\" width=\"72\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 13.5pt;\">\n<th style=\"height: 13.5pt; width: 54pt;\" width=\"72\" height=\"18\">USER_ID<\/th>\n<th style=\"width: 54pt;\" width=\"72\">LOGIN_ID<\/th>\n<th style=\"width: 54pt;\" width=\"72\">PASSWD<\/th>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" height=\"18\">0021<\/td>\n<td align=\"right\">10002<\/td>\n<td align=\"right\">234567<\/td>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" height=\"18\">0020<\/td>\n<td align=\"right\">10001<\/td>\n<td align=\"right\">1234567<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>SQL<\/h2>\n<h3>IN\u3092\u4f7f\u3046\u3002<\/h3>\n<pre class=\"lang:default decode:true\">SELECT * FROM USER_MASTER\r\nWHERE USER_ID IN (SELECT USER_ID FROM AUTHORIZATION )<\/pre>\n<p>\u307e\u305a\u306f\u3001IN\u53e5\u5185\u306eSQL\u304c\u5b9f\u884c\u3055\u308c\u3066\u3001USER_ID\u304c\u53d6\u5f97\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u7d50\u679c\u3092\u3082\u3068\u306bIN\u53e5\u5916\u306e\u6761\u4ef6\u3068\u3057\u3066\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<h3>EXISTS\u3092\u4f7f\u3046\u3002<\/h3>\n<pre class=\"lang:default decode:true\">SELECT * FROM USER_MASTER A\r\nWHERE EXISTS (SELECT * FROM AUTHORIZATION B WHERE A.USER_ID = B.USER_ID )<\/pre>\n<h4>\u7279\u5fb4<\/h4>\n<p>\u300c\u76f8\u95a2\u30b5\u30d6\u30af\u30a8\u30ea\u300d\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u306b\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306f\u304b\u306a\u308a\u9ad8\u3044\u3067\u3059\u3002<\/p>\n<h2>\u5b9f\u884c\u7d50\u679c<\/h2>\n<p>\u3069\u3061\u3089\u3082\u540c\u3058\u7d50\u679c\u306b\u306a\u308b\u3002<\/p>\n<table width=\"236\">\n<tbody>\n<tr>\n<th width=\"72\">USER_ID<\/th>\n<th width=\"72\">DEPT_NO<\/th>\n<th width=\"92\">USER_NAME<\/th>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>1001<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u4e00<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td>1002<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u5b50<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u52d5\u4f5c\u306e\u9055\u3044<\/h2>\n<p>IN\u306f\u4e3b\u554f\u3044\u5408\u308f\u305b\u306eWHERE\u53e5\u306e\u524d\u3001EXISTS\u306f\u5f8c\u3067\u51e6\u7406\u3055\u308c\u308b\u3002\u57fa\u672c\u7684\u306bSQL\u306f\u65e9\u3044\u6bb5\u968e\u3067\u591a\u304f\u306e\u30c7\u30fc\u30bf\u3092\u524a\u304e\u843d\u3068\u3057\u305f\u65b9\u304c\u826f\u3044\u3067\u3059\u3002<\/p>\n<h3>IN\u3068EXISTS\u3069\u3061\u3089\u3092\u4f7f\u3048\u3070\u826f\u3044\u304b\uff1f<\/h3>\n<p>\u7d50\u8ad6\u3068\u3057\u3066\u306f\u3001\u4e3b\u30c6\u30fc\u30d6\u30eb\u3068\u5f93\u30c6\u30fc\u30d6\u30eb\u306e\u3069\u3061\u3089\u304c\u306b\u3088\u3063\u3066\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u8a00\u3048\u3070\u3001IN\u306f\u5f93\u30c6\u30fc\u30d6\u30eb(AUTHORIZATION)\u306e\u65b9\u304c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u3088\u308a\u52b9\u304f\u5834\u5408\u306fIN\u3092\u4f7f\u3044\u3001\u4e3b\u30c6\u30fc\u30d6\u30eb\uff08USER_MASTER\uff09\u3078\u5148\u306bSELECT\u3057\u305f\u65b9\u304c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u9ad8\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u767a\u63ee\u3067\u304d\u308b\u72b6\u6cc1\u3067\u3042\u308c\u3070EXISTS\u3092\u4f7f\u3046\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002\uff08\u3069\u3061\u3089\u306e\u65b9\u304c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u3088\u308a\u52b9\u304f\u304b\u306f\u30ec\u30b3\u30fc\u30c9\u306e\u9078\u629e\u6027\u306b\u3088\u3063\u3066\u5909\u308f\u3063\u3066\u304d\u307e\u3059\u3002\uff09<\/p>\n<p>\u4e3b\u30c6\u30fc\u30d6\u30eb\uff08USER_MASTER\uff09\u306e\u65b9\u304c\u5f93\u30c6\u30fc\u30d6\u30eb(AUTHORIZATION)\u3088\u308a\u3082\u30c7\u30fc\u30bf\u91cf\u304c\u591a\u3044(USER_MASTER\u304c5\u4ef6\u3001AUTHORIZATION\u304c2\u4ef6)\u306e\u3067\u3001EXISTS\u3092\u4f7f\u3063\u305f\u65b9\u304c\u3088\u308a\u9069\u3057\u305f\u9078\u629e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u7d50\u8ad6\u3068\u3057\u3066\u306f\u3001\u3069\u3061\u3089\u304c\u512a\u308c\u3066\u3044\u308b\u304b\u3067\u306f\u306a\u304f\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046IN\u3084EXITS\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u3064\u3044\u3066\u3057\u3063\u304b\u308a\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u8a73\u3057\u304f\u306fJOIN\u3068\u306e\u9055\u3044\u3082\u542b\u3081\u3066\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"zjpmIsf22o\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=14768\">\u3010SQL\u3011IN\u3068EXISTS\u3001JOIN\u306e\u9055\u3044<\/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=14768&#038;embed=true#?secret=zjpmIsf22o\" data-secret=\"zjpmIsf22o\" width=\"500\" height=\"282\" title=\"&#8220;\u3010SQL\u3011IN\u3068EXISTS\u3001JOIN\u306e\u9055\u3044&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf USER_MASTER USER_ID DEPT_NO USER_NAME 0021 1002 \u5c0f\u6cc9 \u7d14\u5b50 0022 1003 \u5c0f\u6cc9 \u4e09\u90ce 0023 1004 \u5c0f\u6cc9 \u82b1\u5b50 0020 1001 \u5c0f\u6cc9 \u7d14\u4e00 A [&hellip;]","protected":false},"author":1,"featured_media":4823,"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\/4727"}],"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=4727"}],"version-history":[{"count":8,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4727\/revisions"}],"predecessor-version":[{"id":20593,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4727\/revisions\/20593"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/4823"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4727"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}