3

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?

2 Answers 2

8
SELECT field1, field2 
FROM table 
WHERE field2 LIKE CONCAT('%', field1, '%');       
Sign up to request clarification or add additional context in comments.

1 Comment

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

Yes, it is. You can use:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.