Error with SQL statement using MySQL

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.
Who is Participating?
Ronak PatelCommented:
Try this one:

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

Open in new window

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 EngineerCommented:
I would actually suggest to go with fulltext search for that kind of search ...
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

bhessionAuthor 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 EngineerCommented:
bhessionAuthor Commented:
Perfect, does exactly what im looking for
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.