19

有没有办法选择在同一字段上出现多个条件中的任何一个的数据?

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

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

有没有办法代替说:

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

任何帮助表示赞赏。

4

7 回答 7

35

当然,最简单的方法是这样的:

select foo from bar where baz in (1,2,3)
于 2008-08-20T12:59:51.743 回答
10
select * from TABLE where field IN (1,2,3)

您还可以方便地将其与仅返回一个字段的子查询结合使用:

    select * from TABLE where field IN (SELECT boom FROM anotherTable)
于 2008-08-20T12:59:58.670 回答
5

或者:

SELECT foo FROM bar WHERE baz BETWEEN 1 AND 3
于 2008-08-20T13:05:32.870 回答
3

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

于 2008-08-20T13:00:01.133 回答
3
WHERE field IN (1, 2, 3)
于 2008-08-20T13:00:01.447 回答
1

你仍然可以使用 in for

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

只是

select * from table where field in ('1','2','3')
于 2008-08-20T13:08:03.003 回答
0

whilein是一个快捷方式or,我不确定如何与 结合inand我是这样做的

 SELECT * FROM table
 WHERE column1='x' AND (column2='y' OR column2='z');
于 2019-01-27T20:38:12.410 回答