Search code examples
mysqlwildcardsql-like

My sql:how to use Wildcard in Subquery?


example:

SELECT country 
FROM data
WHERE city LIKE 
(SELECT LEFT ('jakartada',7));

it's working nicely but if i give delimiter with value:4 ,i must give wildcard like this ---> "%string%" ,where i can give wildcard in the query?


Solution

  • With LIKE you can use the following two wildcard characters in the pattern.

    Character   Description
    %           Matches any number of characters, even zero characters
    _           Matches exactly one character
    \%          Matches one “%” character
    \_          Matches one “_” character
    

    does this query help you?

    SELECT country 
    FROM data
    WHERE city LIKE CONCAT ('%', (SELECT LEFT ('jakartada',7)), '%');