开发者

MySQL - How to use fields in 'LIKE' operator

开发者 https://www.devze.com 2023-01-20 05:46 出处:网络
I want to do a \'select\' in MySQL using the operator \'LIKE\'. But I do not want to use text as a comparison factor. I want to compare text between two fields in same table, like this:

I want to do a 'select' in MySQL using the operator 'LIKE'.

But I do not want to use text as a comparison factor. I want to compare text between two fields in same table, like this:

SELECT field1,field2 FROM table WHERE field2 LIKE %field1开发者_运维百科% ;

Is it possible?


SELECT field1, field2 
FROM table 
WHERE field2 LIKE CONCAT('%', field1, '%');       


Yes, it is. You can use:

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

精彩评论

暂无评论...
验证码 换一张
取 消