17

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

Community
  • 1
  • 1
Al Amin Chayan
  • 2,460
  • 4
  • 23
  • 41
  • Does anyone know the answer for the same question but in Snowflake instead of MySQL? I tried below mentioned solution but it did not work. – Rahul Ghadge Oct 22 '20 at 20:21

1 Answers1

37

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:]]'
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274