有没有办法选择在同一字段上出现多个条件中的任何一个的数据?
示例:我通常会写一个语句,例如:
select * from TABLE where field = 1 or field = 2 or field = 3
有没有办法代替说:
select * from TABLE where field = 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 (1,2,3)
您还可以方便地将其与仅返回一个字段的子查询结合使用:
select * from TABLE where field IN (SELECT boom FROM anotherTable)
或者:
SELECT foo FROM bar WHERE baz BETWEEN 1 AND 3
select * from TABLE where field in (1, 2, 3)
WHERE field IN (1, 2, 3)
你仍然可以使用 in for
select *
from table
where field = '1' or field = '2' or field = '3'
只是
select * from table where field in ('1','2','3')
whilein
是一个快捷方式or
,我不确定如何与 结合in
,and
我是这样做的
SELECT * FROM table
WHERE column1='x' AND (column2='y' OR column2='z');