[SOLVED] How to write a query with multiple LIKE clauses?

Issue

I have a problem with this query:

SELECT * 
FROM posts 
WHERE title LIKE '%samsung%' 
OR title LIKE '%42%' 
AND price >= '100' 
AND price <= '1000000' 
AND shipping = '1' 
AND sale_type = '1' 
LIMIT 0,50

The problem is that when i run the query with 2 or more title LIKE '%%'it shows me only the ones with the title LIKE '%%'

SELECT * 
FROM posts 
WHERE title LIKE '%samsung%' 
AND price >= '100' 
AND price <= '1000000' 
AND shipping = '1' 
AND sale_type = '1'
LIMIT 0,50

Ignoring the other options. But if I run the query with just title LIKE ‘%%’ it works perfect.

Solution

You may try this way:

WHERE title REGEXP 'samsung|42'

More info here: http://forums.mysql.com/read.php?10,392332,392950#msg-392950

Answered By – MillaresRoo

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *