How Do You or Two Like Statements?
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 Error Select Col...
I have tried the following two statements:
SELECT col FROM db.tbl WHERE col (LIKE 'str1' OR LIKE 'str2') AND col2 = numresults in a syntax errorSELECT col FROM db.tbl WHERE page LIKE ('str1' OR 'str2') AND col2 = numresults 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.
8 Answers
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = num
I believe you need WHERE ((page LIKE 'str1') OR (page LIKE 'str2'))
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
Think simple:
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = ...
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.
try SELECT col FROM db.tbl WHERE (col LIKE 'str1' or col LIKE 'str2') AND col2 = num
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
In recent versions of SQL you can use the IN operator:
SELECT col FROM db.tbl WHERE col IN('str1','str2') AND col2 = num