1

I need to write a subquery inside a LIKE statement. This subquery would return me a word that I need to find in the middle of a sentence (that belongs to another field). Is it possible? This is how I'm trying (and failing):

select nm_linha from linhas where cidades_origem like '%SUBQUERY HERE WOULD GO HERE%'
0

1 Answer 1

1

Something like this should work :

select nm_linha from linhas where cidades_origem like CONCAT('%', (subquery_goes_here) ,'%')

For example :

SELECT * 
FROM films
WHERE titre LIKE CONCAT('%', (SELECT  'fella'),  '%')

+---------+------------+
| id      | titre      |
+---------+------------+
|       1 | Goodfellas |
+---------+------------+
1 row in set (0.01 sec)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.