We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Error with SQL statement using MySQL

bhession
bhession asked
on
Medium Priority
453 Views
Last Modified: 2013-11-24
I am attempting to use the below SQL statement. This is clearly not right but I am not sure how to correct it. Could some please show me my mistake?

SELECT * FROM details where SerialNo LIKE '%Blah%'  AND ControllerSerialNo LIKE '%Blah%'  AND (Address1 OR Address2 OR Address3 OR Address4 OR County LIKE '%Blah%'  AND COUNTRY = 'England'

I am basically passing 4 strings from a form to a servlet, SerialNo, ControllerSerialNo, Address and Country. The problem resides in the Address part of the statement. I want to select entries that match the Address string sent to the servlet, in any of the 5 different columns in my database.

If I am unclear in my explanation please dont hesitate to ask me for more info.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
please modify the query

SELECT * FROM details where SerialNo LIKE '%Blah%'  AND ControllerSerialNo LIKE '%Blah%'  AND ((Address1!="") OR (Address2!="") OR (Address3!="") OR (Address4!="")) AND (County LIKE '%Blah%'  OR COUNTRY = 'England');
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
I would actually suggest to go with fulltext search for that kind of search ...
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Kalmax I think maybe you misunderstand the query i am trying to use or create.

Four search criteria passed to servlet 1.SerialNo, 2. ControllerSerialNo, 3. Address, 4. Country

SerialNo looks for similar string in column SerialNo,
ControllerSerialNo looks for a string is in column ControllerSerialNo,
Address lookes for a string similar to it in any of these columns , Address1, Address2, Address3, Address4 or County.
Country searches for a string matching it in Country

angelll, What do you mean?
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:

Author

Commented:
Perfect, does exactly what im looking for
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.