MySql: how to remove special characters from column in query
For similar purposes, you can also rely on a series and GROUP_CONCAT:

SET @str:='abc - 123';
SELECT GROUP_CONCAT(c SEPARATOR '')
FROM (
    SELECT MID(@str, id, 1) AS c FROM myseries
    WHERE id BETWEEN 1 AND LENGTH(@str)
) a
WHERE c REGEXP '[[:alnum:]]';


For this you could keep a myseries table for general use, it can be quickly created with 10,000 rows like this:

CREATE TABLE myseries (id int NOT NULL AUTO_INCREMENT PRIMARY KEY);
INSERT INTO myseries
SELECT NULL FROM information_schema.columns, information_schema.columns c2 LIMIT 10000;


Or create one on the fly from any table large enough:

SET @str:='abc - 123';
SET @len:=LENGTH(@str);
SELECT GROUP_CONCAT(c SEPARATOR '')
FROM (
    SELECT MID(@str, id, 1) AS c
    FROM (
        SELECT @num:=@num+1 AS id
        FROM (SELECT @num:=0) num, yourtable
        WHERE @num&lt;=@len
    ) myseries
) a
WHERE c REGEXP '[[:alnum:]]';