0

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.

2 Answers 2

4

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]%') 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. I'm not that good with MySQL yet so thanks kababayan. :)
0

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]%' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.