<i id='wG1wC'><tr id='wG1wC'><dt id='wG1wC'><q id='wG1wC'><span id='wG1wC'><b id='wG1wC'><form id='wG1wC'><ins id='wG1wC'></ins><ul id='wG1wC'></ul><sub id='wG1wC'></sub></form><legend id='wG1wC'></legend><bdo id='wG1wC'><pre id='wG1wC'><center id='wG1wC'></center></pre></bdo></b><th id='wG1wC'></th></span></q></dt></tr></i><div id='wG1wC'><tfoot id='wG1wC'></tfoot><dl id='wG1wC'><fieldset id='wG1wC'></fieldset></dl></div>
  • <small id='wG1wC'></small><noframes id='wG1wC'>

    • <bdo id='wG1wC'></bdo><ul id='wG1wC'></ul>

    <tfoot id='wG1wC'></tfoot>

        <legend id='wG1wC'><style id='wG1wC'><dir id='wG1wC'><q id='wG1wC'></q></dir></style></legend>

        为一个值检查多列

        Checking multiple columns for one value(为一个值检查多列)
          <tbody id='6CzPN'></tbody>

              <small id='6CzPN'></small><noframes id='6CzPN'>

              <legend id='6CzPN'><style id='6CzPN'><dir id='6CzPN'><q id='6CzPN'></q></dir></style></legend>
                <i id='6CzPN'><tr id='6CzPN'><dt id='6CzPN'><q id='6CzPN'><span id='6CzPN'><b id='6CzPN'><form id='6CzPN'><ins id='6CzPN'></ins><ul id='6CzPN'></ul><sub id='6CzPN'></sub></form><legend id='6CzPN'></legend><bdo id='6CzPN'><pre id='6CzPN'><center id='6CzPN'></center></pre></bdo></b><th id='6CzPN'></th></span></q></dt></tr></i><div id='6CzPN'><tfoot id='6CzPN'></tfoot><dl id='6CzPN'><fieldset id='6CzPN'></fieldset></dl></div>
              • <tfoot id='6CzPN'></tfoot>

                  <bdo id='6CzPN'></bdo><ul id='6CzPN'></ul>

                  本文介绍了为一个值检查多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个表格,其中包含这样的列,例如:

                  id,col1,col2,col3,col4

                  现在,我想检查 col1, col2, col3, col4ANY 是否有传入的值.

                  很长的路要走...

                  SELECT * FROM table WHERE (col1 = 123 OR col2 = 123 OR col3 = 123 OR col4 = 123);

                  我猜它是 IN 的相反版本.

                  有没有更简单的方法来做我想做的事?

                  解决方案

                  您可以使用 IN 谓词,如下所示:

                  SELECT * FROM table WHERE 123 IN(col1, col2, col3, col4);

                  I have a table that has columns like this for example:

                  id,col1,col2,col3,col4
                  

                  Now, I want to check if ANY of col1, col2, col3, col4 have the passed in value.

                  The long way to do it would be..

                  SELECT * FROM table WHERE (col1 = 123 OR col2 = 123 OR col3 = 123 OR col4 = 123);
                  

                  I guess it's the opposite version of IN.

                  Is there an easier way to do what I want?

                  解决方案

                  You can use the IN predicate, like so:

                  SELECT * FROM table WHERE 123 IN(col1, col2, col3, col4);
                  

                  SQL Fiddle Demo


                  it's the opposite version of IN.

                  No it is not, It is the same as using the ORs the way you did in your question.


                  To clarify this:

                  The predicate IN or set membership is defined as1:

                  Where the Value Expression can be either 2:

                  So it is fine to do it this way, using the value expression 123, which is a literal.


                  1, 2: Images from: SQL Queries for Mere Mortals(R): A Hands-On Guide to Data Manipulation in SQL

                  这篇关于为一个值检查多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)

                    <tfoot id='AVeaF'></tfoot>

                    • <i id='AVeaF'><tr id='AVeaF'><dt id='AVeaF'><q id='AVeaF'><span id='AVeaF'><b id='AVeaF'><form id='AVeaF'><ins id='AVeaF'></ins><ul id='AVeaF'></ul><sub id='AVeaF'></sub></form><legend id='AVeaF'></legend><bdo id='AVeaF'><pre id='AVeaF'><center id='AVeaF'></center></pre></bdo></b><th id='AVeaF'></th></span></q></dt></tr></i><div id='AVeaF'><tfoot id='AVeaF'></tfoot><dl id='AVeaF'><fieldset id='AVeaF'></fieldset></dl></div>
                        <tbody id='AVeaF'></tbody>

                          <bdo id='AVeaF'></bdo><ul id='AVeaF'></ul>
                          <legend id='AVeaF'><style id='AVeaF'><dir id='AVeaF'><q id='AVeaF'></q></dir></style></legend>

                          <small id='AVeaF'></small><noframes id='AVeaF'>