0

我有这个客户表:

+----------+----------+---------+
| cliecode | cliename | deleted |
+----------+----------+---------+
|    00001 | ABC      |         |
|    00002 | DEF      |         |
|    00003 | GHI      | yes     |
|    00004 | JKL      |         |
+----------+----------+---------+

我正在执行这样的搜索查询:

SELECT * 
FROM client 
WHERE deleted ='' 
      AND cliecode LIKE '%$_POST[key]%' OR cliename LIKE '%$_POST[key]%' 

我想deleted = ''在条件之前获取第一个like。我怎样才能做到这一点?谢谢。

4

2 回答 2

4

然后OR通过将它们放在括号内来对您的条件进行分组,

select  * 
from    client 
where   deleted ='' and 
       (cliecode like '%$_POST[key]%' or cliename like '%$_POST[key]%')
于 2013-03-14T08:25:04.020 回答
0

您是否在已删除字段中设置了任何默认值?

如果不 -

那么您的查询应该是 -

select * from client 
where 
deleted is null 
and cliecode like '%$_POST[key]%' 
or cliename like '%$_POST[key]%'
于 2013-03-14T08:28:30.777 回答