Mysql – thesql apply regexp_replace for whole column/multiple rows

MySQL

I Have column exe_production inside users_acts table with data like `blah blah blah 10.10.2020 (any date) blah blah.

I need to order this column by date.

My steps:

  1. Get date from string by next query:

    SELECT REGEXP_REPLACE((SELECT exe_production FROM users_acts LIMIT 1), '[^[0-9]{2}[.]{1}[0-9]{2}[.]{1}[0-9]{4}]', '');
    
  2. Convert all results strings to date by DATE_FORMAT statement.

  3. Apply ORDER BY statement.

The problem is that I can't apply first query for multiple rows/values, only by LIMIT 1. How I can solve it?

Best Answer

Your idea was good, but you need STR_TO_DATE and you need the REGEXP_REPLACE in the SELECT not around a subselect

CREATE TABLE users_acts (exe_production varchar(100))
INSERT INTO users_acts VALUES ('blah blah blah 10.10.2020 (any date) blah blah')
SELECT 
    STR_TO_DATE(REGEXP_REPLACE(exe_production,
            '[^[0-9]{2}[.]{1}[0-9]{2}[.]{1}[0-9]{4}]',
            ''),'%d.%m. %Y')
FROM
    users_acts
            
| STR_TO_DATE(REGEXP_REPLACE(exe_production,
           '[^[0-9]{2}[.]{1}[0-9]{2}[.]{1}[0-9]{4}]',
           ''),'%d.%m. %Y') |
| :----------------------------------------------------------------------------------------------------------------------------- |
| 2020-10-10                                                                                                                     |

db<>fiddle here