dowaw80220 2017-01-06 09:44
浏览 69
已采纳

SQL多个OR链查询

I have a single table where I am attempting to access rows via a simple SQL query I think, however, I am misunderstanding the way the OR modifier technically works. The statement I am trying to query is as follows:

SELECT * from table WHERE name OR vehicle OR state OR address LIKE '%input term here%';

This either returns an empty table, or in some instances the entire table. If I pare down the statement to include 0 OR modifiers it works, the trouble begins when I attempt to chain them like above. I'm looking for the simplest way to have one single query for the table, I think this might not be possible the way I'm going about it though. Any ideas?

NOTE: I am sanitizing input, I changed the end of the query for readability.

  • 写回答

2条回答 默认 最新

  • drsxzut183207938 2017-01-06 09:46
    关注

    You need to repeat the LIKE expression for each column, i.e.

    SELECT *
    FROM yourTable
    WHERE name    LIKE '%input term here%' OR
          vehicle LIKE '%input term here%' OR
          state   LIKE '%input term here%' OR
          address LIKE '%input term here%'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?