MySQL - How to use fields in the "LIKE" statement

I want to make a "choice" in MySQL using the "LIKE" operator.

But I do not want to use the text as a comparison factor. I want to compare text between two fields in one table, for example:

SELECT field1, field2 FROM table WHERE field2 LIKE% field1%;

Is it possible?

+3
source share
2 answers
SELECT field1, field2 
FROM table 
WHERE field2 LIKE CONCAT('%', field1, '%');       
+7
source

Yes it is. You can use:

SELECT field1,field2 FROM table WHERE field2 LIKE '%' + field1 '%' ;
0
source

Source: https://habr.com/ru/post/1770151/


All Articles