简体   繁体   中英

SQL query search for two strings

I am trying to run a basic sql query where is search for one of two string:

  1. "Nightly job up"
  2. "Nightly job finished"

I have tried the where command but i getting an empty output. This is the problematic part:

      where execution_location = ('Nightly job up' or Nightly job 'finished');

Please assist, Thanks in advance.

Use IN(...) instead:

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:

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 ).

Therefore your final WHERE clause is equivalent to:

... WHERE execution_location = 0

The right syntax has already been provided by everyone else :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM