Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择。。。。。哪里或_Mysql - Fatal编程技术网

Mysql 选择。。。。。哪里或

Mysql 选择。。。。。哪里或,mysql,Mysql,如果同一字段上出现多个条件中的任何一个,是否有方法选择数据 示例:我通常会写一个语句,例如: select * from TABLE where field = 1 or field = 2 or field = 3 有没有一种方法可以代替说: select * from TABLE where field = 1 || 2 || 3 感谢您的帮助。当然,最简单的方法是: select foo from bar where baz in (1,2,3) 您还可以方便地将其与仅返回一个字段的

如果同一字段上出现多个条件中的任何一个,是否有方法选择数据

示例:我通常会写一个语句,例如:

select * from TABLE where field = 1 or field = 2 or field = 3
有没有一种方法可以代替说:

select * from TABLE where field = 1 || 2 || 3

感谢您的帮助。

当然,最简单的方法是:

select foo from bar where baz in (1,2,3)
您还可以方便地将其与仅返回一个字段的子查询结合使用:

    select * from TABLE where field IN (SELECT boom FROM anotherTable)

从(1、2、3)中字段所在的表格中选择*或:


您仍然可以在中使用

select *
from table
where field  = '1' or field = '2' or field = '3'
只是

select * from table where field in ('1','2','3')

虽然中的是或的快捷方式,我不确定如何将中的与和结合起来,但我是这样做的

 SELECT * FROM table
 WHERE column1='x' AND (column2='y' OR column2='z');
select *
from table
where field  = '1' or field = '2' or field = '3'
select * from table where field in ('1','2','3')
 SELECT * FROM table
 WHERE column1='x' AND (column2='y' OR column2='z');