{"id":3047,"date":"2016-12-15T10:20:30","date_gmt":"2016-12-15T02:20:30","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=3047"},"modified":"2016-12-15T10:20:30","modified_gmt":"2016-12-15T02:20:30","slug":"mysql%e7%9a%84in%e8%bf%90%e7%ae%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3047.html","title":{"rendered":"MySQL\u7684in\u8fd0\u7b97\u7b26"},"content":{"rendered":"<p>=Start=<\/p>\n<h4 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-\u7f18\u7531\uff1a\">\u7f18\u7531\uff1a<\/h4>\n<p>\u5de5\u4f5c\u9700\u8981\uff0c\u5b66\u4e60\u9700\u8981<\/p>\n<h4 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-\u6b63\u6587\uff1a\">\u6b63\u6587\uff1a<\/h4>\n<h5 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-\u53c2\u8003\u89e3\u7b54\uff1a\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<p>MySQL IN \u8fd0\u7b97\u7b26\u7528\u4e8e WHERE \u8868\u8fbe\u5f0f\u4e2d\uff0c\u4ee5\u5217\u8868\u9879\u7684\u5f62\u5f0f\u652f\u6301\u591a\u4e2a\u9009\u62e9\u3002<\/p>\n<h6 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-MySQLIN\u8fd0\u7b97\u7b26\u7684\u8bed\u6cd5\">MySQL IN \u8fd0\u7b97\u7b26\u7684\u8bed\u6cd5<\/h6>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeContent panelContent pdl\">\n<div id=\"highlighter_381622\" class=\"syntaxhighlighter sh-confluence nogutter java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\" title=\"Hint: double-click to select code\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">WHERE column IN (value1,value2,...)<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\">WHERE column NOT IN (value1,value2,...)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5f53 IN \u524d\u9762\u52a0\u4e0a NOT \u8fd0\u7b97\u7b26\u65f6\uff0c\u8868\u793a\u4e0e IN \u76f8\u53cd\u7684\u610f\u601d\uff0c\u5373\u4e0d\u5728\u8fd9\u4e9b\u5217\u8868\u9879\u5185\u9009\u62e9\u3002<\/p>\n<h6 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-MySQLIN\u4f7f\u7528\u5b9e\u4f8b\">MySQL IN \u4f7f\u7528\u5b9e\u4f8b<\/h6>\n<p>\u9009\u53d6 uid \u4e3a 2\u30013\u30015 \u7684\u7528\u6237\u6570\u636e\uff1a<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeContent panelContent pdl\">\n<div id=\"highlighter_507186\" class=\"syntaxhighlighter sh-confluence nogutter java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\" title=\"Hint: double-click to select code\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">SELECT * FROM user WHERE uid IN (<\/code><code class=\"java value\">2<\/code><code class=\"java plain\">,<\/code><code class=\"java value\">3<\/code><code class=\"java plain\">,<\/code><code class=\"java value\">5<\/code><code class=\"java plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<h6 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-MySQLIN\u5b50\u67e5\u8be2\">MySQL IN \u5b50\u67e5\u8be2<\/h6>\n<p>\u66f4\u591a\u60c5\u51b5\u4e0b\uff0cIN \u5217\u8868\u9879\u7684\u503c\u662f\u4e0d\u660e\u786e\u7684\uff0c\u800c\u53ef\u80fd\u662f\u901a\u8fc7\u4e00\u4e2a\u5b50\u67e5\u8be2\u5f97\u5230\u7684\uff1a<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeContent panelContent pdl\">\n<div id=\"highlighter_685550\" class=\"syntaxhighlighter sh-confluence nogutter java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\" title=\"Hint: double-click to select code\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">SELECT * FROM article WHERE uid IN (SELECT uid FROM user WHERE status=<\/code><code class=\"java value\">0<\/code><code class=\"java plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5728\u8fd9\u4e2a SQL \u4f8b\u5b50\u91cc\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u67e5\u51fa\u6240\u6709\u72b6\u6001\u4e3a 0 \u7684\u7528\u6237\uff08\u53ef\u80fd\u662f\u88ab\u7981\u6b62\uff09\u7684\u6240\u6709\u6587\u7ae0\u3002\u9996\u5148\u901a\u8fc7\u4e00\u4e2a\u67e5\u8be2\u5f97\u5230\u6240\u6709\u6240\u6709 status=0 \u7684\u7528\u6237\uff1a<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeContent panelContent pdl\">\n<div id=\"highlighter_752401\" class=\"syntaxhighlighter sh-confluence nogutter java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\" title=\"Hint: double-click to select code\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">SELECT uid FROM user WHERE status=<\/code><code class=\"java value\">0<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7136\u540e\u5c06\u67e5\u8be2\u7ed3\u679c\u4f5c\u4e3a IN \u7684\u5217\u8868\u9879\u4ee5\u5b9e\u73b0\u6700\u7ec8\u7684\u67e5\u8be2\u7ed3\u679c\uff0c\u6ce8\u610f\u5728\u5b50\u67e5\u8be2\u4e2d\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u662f\u4e00\u4e2a\u5b57\u6bb5\u5217\u8868\u9879\u3002<\/p>\n<h6 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-MySQLIN\u8fd0\u7b97\u7b26\u7684\u6548\u7387\u95ee\u9898\">MySQL IN \u8fd0\u7b97\u7b26\u7684\u6548\u7387\u95ee\u9898<\/h6>\n<p><strong>\u5982\u679c IN \u7684\u5217\u8868\u9879\u662f\u786e\u5b9a\u7684\uff0c\u90a3\u4e48\u53ef\u4ee5\u7528\u591a\u4e2a OR \u6765\u4ee3\u66ff<\/strong>\uff1a<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeContent panelContent pdl\">\n<div id=\"highlighter_815147\" class=\"syntaxhighlighter sh-confluence nogutter java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\" title=\"Hint: double-click to select code\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">SELECT * FROM user WHERE uid IN (<\/code><code class=\"java value\">2<\/code><code class=\"java plain\">,<\/code><code class=\"java value\">3<\/code><code class=\"java plain\">,<\/code><code class=\"java value\">5<\/code><code class=\"java plain\">)<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java comments\">\/\/ \u7b49\u6548\u4e3a\uff1a<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\">SELECT * FROM user WHERE (uid=<\/code><code class=\"java value\">2<\/code>\u00a0<code class=\"java plain\">OR uid=<\/code><code class=\"java value\">3<\/code>\u00a0<code class=\"java plain\">OR uid=<\/code><code class=\"java value\">5<\/code><code class=\"java plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><span style=\"color: #ff0000;\">\u4e00\u822c\u8ba4\u4e3a\uff0c\u5982\u679c\u662f\u5bf9\u7d22\u5f15\u5b57\u6bb5\u8fdb\u884c\u64cd\u4f5c\uff0c\u4f7f\u7528 OR \u6548\u7387\u9ad8\u4e8e IN\uff0c\u4f46\u5bf9\u4e8e\u5217\u8868\u9879\u4e0d\u786e\u5b9a\u7684\u65f6\u5019\uff08\u5982\u9700\u8981\u5b50\u67e5\u8be2\u5f97\u5230\u7ed3\u679c\uff09\uff0c\u5c31\u5fc5\u987b\u4f7f\u7528 IN \u8fd0\u7b97\u7b26\u3002\u53e6\u5916\uff0c\u5bf9\u4e8e\u5b50\u67e5\u8be2\u8868\u6570\u636e\u5c0f\u4e8e\u4e3b\u67e5\u8be2\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u9002\u7528 IN \u8fd0\u7b97\u7b26\u7684\u3002<\/span><\/p>\n<h5 id=\"MySQL\u7684in\u8fd0\u7b97\u7b26-\u53c2\u8003\u94fe\u63a5\uff1a\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a class=\"external-link\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/comparison-operators.html#function_in\" target=\"_blank\" rel=\"nofollow\">http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/comparison-operators.html#function_in<\/a><\/li>\n<li><a class=\"external-link\" href=\"http:\/\/www.bkjia.com\/Mysql\/1084095.html\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.bkjia.com\/Mysql\/1084095.html<\/a><\/li>\n<li><a class=\"external-link\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/any-in-some-subqueries.html\" target=\"_blank\" rel=\"nofollow\">http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/any-in-some-subqueries.html<\/a><\/li>\n<li><a class=\"external-link\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/logical-operators.html#operator_or\" target=\"_blank\" rel=\"nofollow\">http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/logical-operators.html#operator_or<\/a><\/li>\n<li><a href=\"http:\/\/blog.mimvp.com\/2015\/07\/mysql-is-greater-than-less-than-comparison-of-inorbetween\/\">MySQL\u4e2d\u5927\u4e8e\u5c0f\u4e8e\uff0cIN\uff0cOR\uff0cBETWEEN\u6027\u80fd\u6bd4\u8f83<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u5de5\u4f5c\u9700\u8981\uff0c\u5b66\u4e60\u9700\u8981 \u6b63\u6587\uff1a \u53c2\u8003\u89e3\u7b54\uff1a MySQL IN \u8fd0\u7b97\u7b26\u7528\u4e8e WHERE \u8868\u8fbe [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23,7],"tags":[696,433,16],"class_list":["post-3047","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","category-programing","tag-between","tag-in","tag-mysql"],"views":2770,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3047"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3047\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}