0

I have a read only database. where i want to compare two string. But in the database some column value name has included some special character but i want to compare another string with this string without special character.

For example, In DB the column value name is BMW 3-SERIES. And i have another string BMW3SERIES. So, i want to remove - and space then compare two string in a where condition. Is both string equal or not ?

I am stuck how to remove special characters from model_name .

SELECT * FROM VENDOR WHERE model_name = "BMW3SERIES"

What should be the query?

Md. Abu Farhad
  • 373
  • 5
  • 21

1 Answers1

1

On MySQL 8+, you could use REGEXP_REPLACE to remove what you deem as special characters, for example:

SELECT *
FROM VENDOR
WHERE REGEXP_REPLACE(model_name, '[ -]+', '') = 'BMW3SERIES';

You may add whatever characters you wish to the above character class [ -]+.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360