{"id":14859,"date":"2021-11-07T18:14:12","date_gmt":"2021-11-07T09:14:12","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=14859"},"modified":"2023-05-27T23:14:10","modified_gmt":"2023-05-27T14:14:10","slug":"%e3%80%90sql%e3%80%91%e3%80%8cwhere-or%e3%80%8d%e3%81%8b%e3%80%8cunion%e3%80%8d%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%9f%e6%96%b9%e3%81%8c%e8%89%af%e3%81%84%e3%81%8b%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=14859","title":{"rendered":"\u3010SQL\u3011\u300cWHERE + OR\u300d\u304b\u300cUNION\u300d\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044\u304b\uff1f"},"content":{"rendered":"<p>\u300cWHERE + OR\u300d\u3068\u300cUNION\u300d\u306f\u540c\u5024\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u3042\u308c\u3070\u3001\u3069\u3061\u3089\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<h2>WHERE + OR<\/h2>\n<ul>\n<li>OR\u3092\u4f7f\u3063\u3066\u3057\u307e\u3046\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u4f7f\u308f\u308c\u307e\u305b\u3093\u3002<\/li>\n<li>\u305f\u3060\u3001\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u56de\u6570\u3092\u6e1b\u3089\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">SELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nWHERE \r\n  (\u30ab\u30e9\u30e01 = \"A\") OR\r\n  (\u30ab\u30e9\u30e02 = \"A\") OR\r\n  (\u30ab\u30e9\u30e03 = \"A\")<\/pre>\n<p>\u4e0a\u8a18SQL\u306e\u5b9f\u884c\u8a08\u753b\u3092\u898b\u308c\u3070\u308f\u304b\u308a\u307e\u3059\u304c\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30b9\u30ad\u30e3\u30f3\u3067\u306f\u306a\u304f\u30d5\u30eb\u30c6\u30fc\u30d6\u30eb\u30b9\u30ad\u30e3\u30f3\u304c\u4f7f\u308f\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u306f1\u5ea6\u306e\u30a2\u30af\u30bb\u30b9\u3067\u3059\u307f\u307e\u3059\u3002<\/p>\n<h2>UNION<\/h2>\n<ul>\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u308f\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<li>\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u56de\u6570\u304c\u5897\u3048\u307e\u3059\u3002<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">SELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n  WHERE (\u30ab\u30e9\u30e01 = \"A\") \r\nUNION\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n  WHERE (\u30ab\u30e9\u30e02 = \"A\") \r\nUNION\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n  WHERE (\u30ab\u30e9\u30e03 = \"A\")<\/pre>\n<p>\u4e0a\u8a18\u4f8b\u3067\u8a00\u3048\u3070\u3001\u30ab\u30e9\u30e01\u3001\u30ab\u30e9\u30e02\u3001\u30ab\u30e9\u30e03\u306b\u5bfe\u3057\u3066CREATE INDEX\u306b\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4ed8\u4e0e\u3059\u308c\u3070\u54043\u56de\u306eWHERE\u53e5\u306eSELECT\u6587\u306e\u5b9f\u884c\u3092\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3067\u9ad8\u901f\u5316\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\uff08\u305d\u306e\u5206\u30c6\u30fc\u30d6\u30eb\u306b\u306f3\u56de\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff09<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>\u300c1\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u30d5\u30eb\u30b9\u30ad\u30e3\u30f3\u3059\u308b\u65b9\u304c\u901f\u3044\u300d<\/strong><\/span>\u304b\u3001<span style=\"color: #ff0000;\"><strong>\u300c\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30b9\u30ad\u30e3\u30f3\u3092\u3057\u3066\u7d44\u307f\u5408\u308f\u305b\u308b\u65b9\u304c\u901f\u3044\u300d<\/strong><\/span>\u304b\u306e\u3069\u3061\u3089\u304b\u306b\u306a\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u72b6\u6cc1\u306b\u3088\u3063\u3066\u4f7f\u3044\u5206\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>\u30c6\u30fc\u30d6\u30eb\u5168\u4f53\u306e\u884c\u6570<\/li>\n<li>\u691c\u7d22\u6761\u4ef6\u306e\u9078\u629e\u7387\uff08\u30ec\u30b3\u30fc\u30c9\u306e\u30d2\u30c3\u30c8\u7387\uff09<\/li>\n<\/ul>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u884c\u6570\u304c\u5927\u304d\u304f\u3001\u691c\u7d22\u6761\u4ef6\u306e\u9078\u629e\u7387\u304c\u5c0f\u3055\u3044\u5834\u5408\u306f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30b9\u30ad\u30e3\u30f3\u306e\u52b9\u679c\u304c\u304b\u306a\u308a\u9ad8\u3044\u72b6\u6cc1\u306b\u306a\u308b\u306e\u3067WHERE+ ON\u3088\u308a\u3082UNION\u306e\u65b9\u304c\u512a\u308c\u305f\u30c1\u30e7\u30a4\u30b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>CASE\u5f0f\u3092\u4f7f\u3063\u305f\u9ad8\u901f\u5316<\/h2>\n<p>\u307e\u305f\u3001CASE\u5f0f\u304c\u4f7f\u3048\u308b\u5834\u5408\uff08\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\uff09\u306f\u4e00\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3000\u304b\u3064\u3000\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30b9\u30ad\u30e3\u30f3\u3092\u884c\u3046\u3053\u3068\u304c\u53ef\u80fd\u306a\u305f\u3081\u3067\u304d\u308b\u3060\u3051CASE\u5f0f\u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true \">SELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n  WHERE CASE WHEN \u30ab\u30e9\u30e01 = \"A\" THEN \u30ab\u30e9\u30e01 = \"A\"\r\n      WHEN \u30ab\u30e9\u30e02 = \"A\" THEN \u30ab\u30e9\u30e02 = \"A\"\r\n      WHEN \u30ab\u30e9\u30e03 = \"A\" THEN \u30ab\u30e9\u30e03 = \"A\"\r\n    END<\/pre>\n","protected":false},"excerpt":{"rendered":"\u300cWHERE + OR\u300d\u3068\u300cUNION\u300d\u306f\u540c\u5024\u306b\u306a\u308a\u307e\u3059\u3002 \u3067\u3042\u308c\u3070\u3001\u3069\u3061\u3089\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u304b\u3002 WHERE + OR OR\u3092\u4f7f\u3063\u3066\u3057\u307e\u3046\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u4f7f\u308f\u308c\u307e\u305b\u3093\u3002 \u305f\u3060\u3001\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u56de\u6570\u3092\u6e1b\u3089\u3059\u3053\u3068 [&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\/14859"}],"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=14859"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/14859\/revisions"}],"predecessor-version":[{"id":20580,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/14859\/revisions\/20580"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14859"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}