xjshiya
xjshiya

Reputation: 925

Performing where clause

I have this client table:

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

And I'm performing a search query like this:

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

I want to fetch the deleted = '' first before the like condition. How can I do this? Thanks.

Upvotes: 0

Views: 37

Answers (2)

John Woo
John Woo

Reputation: 263683

then group your OR condition by putting them inside parenthesis,

select  * 
from    client 
where   deleted ='' and 
       (cliecode like '%$_POST[key]%' or cliename like '%$_POST[key]%')

Upvotes: 4

Piyas De
Piyas De

Reputation: 1764

have you set any defualt value in deleted field?

if not -

then your query should be -

select * from client 
where 
deleted is null 
and cliecode like '%$_POST[key]%' 
or cliename like '%$_POST[key]%'

Upvotes: 0

Related Questions