views:

38

answers:

2

Hi!

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?

+4  A: 
SELECT field1, field2 
FROM table 
WHERE field2 LIKE CONCAT('%', field2, '%');
RedFilter
Thank you very much!
Paulocoghi
This solution does not work. I found the correct, that is:
Paulocoghi
SELECT field1,field2 FROM table WHERE field2 LIKE CONCAT('%', field2, '%');
Paulocoghi
If you wish, you may edit your answers, and points will remain with you. :)
Paulocoghi
@Paulocoghi: done
RedFilter
A: 

Yes, it is. You can use:

SELECT field1,field2 FROM table WHERE field2 LIKE '%' + field1 '%' ;
Pablo Santa Cruz