LIKE OR on nested select?

SELECT l.`s_slug`
      FROM test.`oc_t_city` l  
     WHERE l.s_slug not IN (SELECT p.asciiname
                    FROM hello.`geoname` p


WHERE `feature code` not in ('ADM1', 'ADM1H', 'ADM2', 'ADM2H', 'ADM3', 'ADM3H', 'ADM4', 'ADM4H', 'ADM5', 'ADMD', 'ADMDH', 'PCLI'))

How to add LIKE OR statement before second select?

WHERE l.s_slug like '%nested select resutls%' or l.s_slug like 'nested select resutls%' etc.???

I need to fetch all results from both tables then somehow compare them for match using LIKE?

You just add it as a condition on the outer select

NOTE: ‘%search value%’ will automaticaly contain ‘search value%’ so there’s no need to include it twice.

SELECT l.`s_slug`
  FROM test.`oc_t_city` l  
 WHERE l.slug LIKE '%nested select results%'
   AND l.s_slug not IN (SELECT p.asciiname
                          FROM hello.`geoname` p
                         WHERE `feature code` NOT IN ('ADM1', 'ADM1H', 'ADM2', 'ADM2H', 'ADM3', 'ADM3H', 'ADM4', 'ADM4H', 'ADM5', 'ADMD', 'ADMDH', 'PCLI'))
1 Like

Buddy thanks so much.

$q = mysql_query("
    SELECT p.id,l.pk_i_id
    FROM   hello.`geoname_ni` p, test.oc_t_city l
    WHERE  l.s_slug like '%p.asciiname%' 

");

Why this doesn’t work:

WHERE l.s_slug like '%p.asciiname%'

Because that’s not what you asked in the previous example…

$q = mysql_query("SELECT p.id
                       , l.pk_i_id
                    FROM hello.geoname_ni p
                    JOIN test.oc_t_city l ON l.s_slug LIKE CONCAT('%', p.asciiname, '%')");
1 Like

Buddy I am sorry just playing with many queries.

Really appreciate your support.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.