Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple search and find in sql

Tags:

sql

mysql

I'm new to SQL and I'm stuck on a multiple find in SQL.

Here I'm trying to search table1 in the three columns. But I'm stuch in trying to find two phrases. I'm trying with an OR statement.

If I remove OR LIKE '%paris%' it works but how do I find multiple words/phrases. And would this statement be case sensitive?

I'm also using MySQL to run the above.

SELECT * FROM `table1`
WHERE
CONCAT_WS('|',`target_1`,`target_2`,`target_3`) 
LIKE '%london%' OR LIKE '%paris%'
like image 610
John K Bell Avatar asked Aug 24 '26 16:08

John K Bell


1 Answers

In your code your second condition is sintactically wrong because is missing the a part for the match

so you should repeat the condition as

SELECT * 
FROM `table1`
WHERE CONCAT_WS('|',`target_1`,`target_2`,`target_3`) LIKE '%london%' 
OR CONCAT_WS('|',`target_1`,`target_2`,`target_3`) LIKE '%paris%'
like image 188
ScaisEdge Avatar answered Aug 26 '26 08:08

ScaisEdge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!