Reputation: 116187
I have tried the following two statements:
SELECT col FROM db.tbl WHERE col (LIKE 'str1' OR LIKE 'str2') AND col2 = num
results in a syntax errorSELECT col FROM db.tbl WHERE page LIKE ('str1' OR 'str2') AND col2 = num
results in "Truncated incorrect DOUBLE value: str1" and "Truncated incorrect DOUBLE value: str2" for what looks like every result. However, no results are actually returned.I figured one of the two statements would work, but they aren't.
Upvotes: 56
Views: 187263
Reputation: 13855
try
SELECT col FROM db.tbl WHERE (col LIKE 'str1' or col LIKE 'str2') AND col2 = num
Upvotes: 2
Reputation: 101380
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = num
Upvotes: 100
Reputation: 71
I assume what you want is,
SELECT col FROM db.tbl WHERE col LIKE '%str[12]%' AND col2 = num
That will literally find all cases where (col like %str1% or col like %str2%) AND col2 = num
Upvotes: 3
Reputation: 7
In recent versions of SQL you can use the IN
operator:
SELECT col FROM db.tbl WHERE col IN('str1','str2') AND col2 = num
Upvotes: 0
Reputation: 1972
USE %
at the Start and End of the String. So that it will check the Sub-Strings as well
SELECT col FROM db.tbl WHERE (col LIKE '%str1%' OR col LIKE '%str2%') AND col2 = num
Upvotes: 6
Reputation: 45533
The "OR" operator applies to expressions. "LIKE 'str1'" and "LIKE 'str2'" are not valid expressions, since the "LIKE" operator requires both a left hand side and a right hand side.
page LIKE ('str1' OR 'str2')
would first try to OR together 'str1' and 'str2', giving the value TRUE. It would then try and evaluate page LIKE TRUE
, and report an error.
Upvotes: 3
Reputation: 33453
I believe you need WHERE ((page LIKE 'str1') OR (page LIKE 'str2'))
Upvotes: 5
Reputation: 55123
Think simple:
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = ...
Upvotes: 2