I need to search table field contains special characters. I found a solution given here something like:
SELECT *
FROM `tableName`
WHERE `columnName` LIKE "%#%"
OR `columnName` LIKE "%$%"
OR (etc.)
But this solution is too broad. I need to mention all the special characters. But I want something which search something like:
SELECT *
FROM `tableName`
WHERE `columnName` LIKE '%[^a-zA-Z0-9]%'
That is search column which contains not only a-z, A-Z and 0-9 but some other characters also. Is it possible with MYSQL
MySQL LIKE operator checks whether a specific character string matches a specified pattern. Pattern matching using SQL simple regular expression comparison. Returns 1 (TRUE) or 0 (FALSE). If either expr or pat is NULL, the result is NULL.
Use regexp
SELECT *
FROM `tableName`
WHERE `columnName` REGEXP '[^a-zA-Z0-9]'
This would select all the rows where the particular column contain atleast one non-alphanumeric character.
or
REGEXP '[^[:alnum:]]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With