Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helo, im just having a problem in mysql query, i am making a search query for my
customer to retrieve customer information, but im having trouble in using the OR and AND in my query, when i put an OR e.g(OR email LIKE '%search_customer%') my query works but the query retrieve all the information and disregard my AND statement e.g
(user_status = 'active') but when i remove the OR my query works pretty well,
but i need the OR statement to search more than 2 fields in my table and select all the user_status = "active" as well, is there something wrong with my query? Please help me cause i really need this query to be fixed cause i will be needing this kind of data retrieving in some of my module, Thank you very much

SQL
SELECT *
FROM tblusers
WHERE
business_name LIKE '%search_customer%' OR emal LIKE '%search_customer%'
AND user_status = 'active';
ORDER by business_name ASC
Posted
Updated 20-Jul-11 20:19pm
v2

You have to rewrite the SQL statement to

SQL
SELECT *
FROM tblusers
WHERE
(business_name LIKE "%search_customer%" OR emal LIKE "%search_customer%")
AND user_status = "active"
ORDER by business_name ASC


Use are missing "(" and ")" between business_name and emal.

Your WHERE statement is like:

business_name OR emal OR user_status = "active"
 
Share this answer
 
v3
Comments
Sandeep Mewara 16-May-11 4:39am    
my 5!
Kim Togo 16-May-11 4:41am    
Thanks :-)
Well, I tried your SQL and, other than the semi-colon in the wrong place, it works fine (I take it that emal. is meant to be email and is just a typo in your question and not in the actual SQL). I would advise you to include the field names in your query rather than using the asterisk to select all fields, but that is just me.
 
Share this answer
 
Thanks Kim Togo6 :) i have test the new code and its work, to think that i am just missing a
"( )" in the query, thank you again, you saved my day!
 
Share this answer
 
Comments
Kim Togo 16-May-11 4:20am    
You are welcome. Please use "Add Comment" under Solution, or else no email is sent to me about your update :-)
[no name] 16-May-11 4:33am    
carlo beatisula - 7 mins ago
okay, thanks again for the help, would you mind if i ask for you email add,
just want to have connections with other people in this industry, ^_^
Kim Togo 16-May-11 4:41am    
Yes of course. Search me up in linkedin.com.
[no name] 17-May-11 1:13am    
what is your email add in linkedin.com?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900