当前位置: 动力学知识库 > 问答 > 编程问答 >

ms access - Update specific values in more than one column - SQL

问题描述:

I have a table that contains two columns, both have email values.

I want to create a query that update a specific data in both columns.

For example if I have two records of the email '[email protected]' in one column and three records of '[email protected]' in the other column I want them both to be updated.

Here for example I want that all the '[email protected]' will be '[email protected]':

My question is how the query should look like.

网友答案:

The simplest way is to run two update statements:

update table
    set col1 = <newval>
    where col1 = <oldval>;

update table
    set col2 = <newval>
    where col2 = <oldval>;

This begs of the question of why two columns are storing the same data. Perhaps you need to review your data structure and use a junction table for this information.

网友答案:

If you insist of one statement:

update table
     set col1 = iif(col1 = 'aa', 'bb', col1),
         col2 = iif(col2 = 'aa', 'bb', col2)
where col1 = 'aa' or col2 = 'aa'
分享给朋友:
您可能感兴趣的文章:
随机阅读: