Find if any of the rows partially match a string
You can use LOCATE()
– as in the other answer – or LIKE
:
SELECT *
FROM site_core_antispam_banned_domain
WHERE 'subdomain.com' LIKE CONCAT('%', domain_name, '%') ;
The above will look for domains that match any part of a given string. If you specifically wanted domains matching the right side of the string (for instance, if the domain to match against was somedomain.com.ro
and you were only interested in *.com.ro
results), you could make the pattern more specific:
SELECT *
FROM site_core_antispam_banned_domain
WHERE 'subdomain.com' LIKE CONCAT('%', domain_name) ;
I think all you need is Locate function in MySQL as:
SELECT domain_id,domain_name as a
FROM site_core_antispam_banned_domain
where Locate(domain_name,'subdomain.com')!=0;
Hope this helps.
Try it:
SELECT *
FROM site_core_antispam_banned_domain
WHERE RIGHT(domain_name,10)='domain.com';