[英]SQL query search for two strings
I am trying to run a basic sql query where is search for one of two string: 我试图运行一个基本的SQL查询,其中搜索两个字符串之一:
I have tried the where command but i getting an empty output. 我尝试了where命令,但输出为空。 This is the problematic part:
这是有问题的部分:
where execution_location = ('Nightly job up' or Nightly job 'finished');
Please assist, Thanks in advance. 请协助,在此先感谢。
Use IN(...)
instead: 使用
IN(...)
代替:
where execution_location in ('Nightly job up', 'Nightly job finished');
This is the way to compare multiple values in one clause. 这是在一个子句中比较多个值的方法。
对于MySQL或Transact-SQL,您的where字符串应为:
WHERE (execution_location = 'Nightly job up' OR execution_location = 'Nightly job finished');
Try: 尝试:
WHERE execution_location IN ('Nightly job up, 'Nightly job finished');
or, if what you want is finding every string starting with Nightly job: 或者,如果您要查找每个以Nightly job开头的字符串:
WHERE execution_location LIKE 'Nightly job%'
尝试
where execution_location in ('Nightly job up', 'Nightly job finished');
Your expression: 您的表情:
('Nightly job up' or 'Nightly job finished')
... is evaluated as a boolean expression, and results in 0 (or FALSE
) (because strings evaluate as FALSE
). ...被评估为布尔表达式,结果为0(或
FALSE
)(因为字符串的评估结果为FALSE
)。
Therefore your final WHERE
clause is equivalent to: 因此,您最终的
WHERE
子句等效于:
... WHERE execution_location = 0
The right syntax has already been provided by everyone else :) 其他人已经提供了正确的语法:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.