mysql查询where子句使用AND和OR [英] mysql query where clause using AND and OR

查看:49
本文介绍了mysql查询where子句使用AND和OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决这个问题吗:

Can someone help me with this query:

 SELECT SQL_CALC_FOUND_ROWS * 
          FROM Punches
          WHERE Serial LIKE '%123%'
          OR Badge LIKE '%123%'
          OR Search_Date LIKE '%123%'
          OR Punch_Time LIKE '%123%'
          OR Device_Name LIKE '%%'
          AND Company_ID = '0002'
          LIMIT 0, 20

本质上,我想搜索所有这些类似于 123 但必须有 Company_ID = '0002' 的字段.此查询返回没有 Company_ID = '0002'

Essentially I want to search all these fields that are LIKE 123 BUT have to have Company_ID = '0002'. This query returns rows that do not have a Company_ID = '0002'

推荐答案

试试这个...

 SELECT 
    SQL_CALC_FOUND_ROWS * 
 FROM 
    Punches
 WHERE 
    (Company_ID = '0002') AND 
    (Serial LIKE '%123%'
     OR Badge LIKE '%123%'
     OR Search_Date LIKE '%123%'
     OR Punch_Time LIKE '%123%'
     OR Device_Name LIKE '%%')
 LIMIT 0, 20

这篇关于mysql查询where子句使用AND和OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆