MariaDB Update Column Values Based on Another Column’s Value

mariadb

I have a column 'StormID' 'Basin' which both hold text based values.

StormID Basin
EP012018 NEP
EP022018 NEP
CP012018 NEP
<– I want this value to change to NCP if the first 2 characters are 'CP' in the StormID column.

Thanks for any suggestions.
Regards,
Bryan

Best Answer

You can use left() to get the first n characters of a string.

UPDATE elbat
       SET basin = 'NCP'
       WHERE left(stormid, 2) = 'CP';