问题描述
|
我在一张桌子上有5列。我想执行多字段搜索。这是可能的...
Table - T
colmun - TC1,TC2,TC3,TC4,TC5
实际查询
select * from T
where TC1=\'search\' or TC2=\'search\' or TC3=\'search\'
or TC4=\'search\' or TC5=\'search\' or
预期查询
select * from T where <single condition > in (\"searc\")
解决方法
您可以使用CONTAINS谓词通过指定要搜索的列列表来查询多个列。这些列必须来自同一表。
select * from T where CONTAINS( (TC1,TC2,TC3,TC4,TC5),\'search\')
, 如果使用CASE语句,则只需指定一次“ 4”参数。
select *
from T
where case \'search\'
when TC1 then 1
when TC2 then 1
when TC3 then 1
when TC4 then 1
when TC5 then 1
else 0
end = 1