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 - 从数据库选择坳。tbl,其中col(比如'str1'或'str2')和col2 = num会导致语法错误
-
SELECT 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. - 从数据库选择坳。在tbl中,类似('str1'或'str2')和col2 = num的页面会导致“截断不正确的双值:str1”和“截断不正确的双值:str2”,因为每个结果看上去都是这样。然而,实际上没有返回结果。
I figured one of the two statements would work, but they aren't.
我想这两个表述中的一个是成立的,但它们不是。
6 个解决方案
#1
34
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = num
#2
2
Think simple:
认为简单:
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = ...
#3
2
I believe you need WHERE ((page LIKE 'str1') OR (page LIKE 'str2'))
我相信你需要(像str1这样的页面)或者(像str2这样的页面)
#4
1
try SELECT col FROM db.tbl WHERE (col LIKE 'str1' or col LIKE 'str2') AND col2 = num
尝试从db中选择col。tbl在其中(col如'str1'或col如'str2')和col2 = num
#5
1
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
#6
0
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.
“OR”运算符适用于表达式。像“str1”和“LIKE‘str2’”都不是有效的表达式,因为“LIKE”操作符需要左手边和右手边。
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.
首先尝试或组合'str1'和'str2',使值为真。然后它会尝试像TRUE那样评估页面,并报告错误。
#1
34
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = num
#2
2
Think simple:
认为简单:
SELECT col FROM db.tbl WHERE (col LIKE 'str1' OR col LIKE 'str2') AND col2 = ...
#3
2
I believe you need WHERE ((page LIKE 'str1') OR (page LIKE 'str2'))
我相信你需要(像str1这样的页面)或者(像str2这样的页面)
#4
1
try SELECT col FROM db.tbl WHERE (col LIKE 'str1' or col LIKE 'str2') AND col2 = num
尝试从db中选择col。tbl在其中(col如'str1'或col如'str2')和col2 = num
#5
1
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
#6
0
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.
“OR”运算符适用于表达式。像“str1”和“LIKE‘str2’”都不是有效的表达式,因为“LIKE”操作符需要左手边和右手边。
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.
首先尝试或组合'str1'和'str2',使值为真。然后它会尝试像TRUE那样评估页面,并报告错误。