SQL query to prepend prefix to existing value in a field

后端 未结 4 744
夕颜
夕颜 2021-01-31 04:12

I have searched and searched for an answer to this, and I think this must be child\'s play for anyone who KNOWS SQL (which is not me).

I want to insert a prefix to the v

相关标签:
4条回答
  • 2021-01-31 04:21
    update tablename set title = 'Mr. ' || title where ....
    
    0 讨论(0)
  • 2021-01-31 04:22

    UPDATE jos_content SET title = CONCAT('Mr. ', title) WHERE 1

    Before testing the query do make a database backup.

    0 讨论(0)
  • 2021-01-31 04:36

    just do it like this

    If, for example, I want to add +symbol before the countrycode:

    UPDATE [masters].[country] SET Countrycode = '+' +Countrycode
    
    0 讨论(0)
  • 2021-01-31 04:38

    You have no other conditions like update this in all rows then you can try

    UPDATE jos_content SET title = CONCAT('Mr. ', title) 
    

    if you want to update conditionally that means particular row needs to update the you can use

     UPDATE jos_content SET title = CONCAT('Mr. ', title)  where fiedl_name ='condition'
    
    eg: UPDATE jos_content SET title = CONCAT('Mr. ', title)  where id = '1'
    

    this will update only one row which contain id=1.

    any way before doing this should keep a backup

    0 讨论(0)
提交回复
热议问题