Search code examples
mysqlsqldremio

How to only edit certain strings in column?


I have table in a sql table that looks like this:

column
1
2
welcome from henry
welcome from beth
welcome
3
4

How do I only edit the values that have 'Welcome from' to become only 'Welcome'?

New column:

1
2
welcome
welcome
welcome
3
4

I can not edit the table, have to do this in select statement.


Solution

  • You could use:

    UPDATE tab
    SET col = 'welcome'
    WHERE col LIKE 'welcome %'
    

    EDIT:

    Unfortunately I cant update any tables, I can only do it select statements

    SELECT CASE WHEN col LIKE 'welcome %' THEN 'welcome' ELSE col END AS col
    FROM tab