首页 > 解决方案 > 查询以在整个表上搜索关键字

问题描述

我有下表:

https://imgur.com/QXDtXXb

当我执行查询时:

SELECT Description, Solution, ReportBy from KMS where Description or Effect or Cause or Check1 or Solution or ReportBy like '%test%'

这是结果:

https://imgur.com/VRLUAzB

我可以预期车道 2、3、4、6、7、8、9 和 10 是结果,我做错了什么?

问候, FMendonça

标签: sqlite

解决方案


这个查询

SELECT Description, Solution, ReportBy 
from KMS 
where Description
or Effect
or Cause 
or Check1 
or Solution 
or ReportBy like '%test%'

将只返回具有的行的结果

  • ReportBy like %test%'
  • 1在任何其他列中

那是因为where Description本质上是一个布尔测试。如果要检查多列中的值,则必须分别检查每一列,例如:

WHERE Description like '%test%'
OR Effect like '%test%'
.
.
OR ReportBy like '%test%'

推荐阅读