When modifying a record in MySQL, the update operation field = field + string

When modifying a record in MySQL, the update operation field = field + string

In some scenarios, we need to modify our varchar type fields, and the result of the modification is the concatenation of two fields or the concatenation of a field + a string.

As shown below, we want to modify the name in the xx_role table to name+id.

In MySQL, if we operate directly through "+", an error will be prompted.

The operator "+" is used to add numbers. Here, the keyword concat is needed to indicate concatenation.

Similarly, we can also use field + string to concatenate.

Here we will briefly talk about the "+" operation, which is used to add numeric fields, as shown below:

Supplement: Use update in mysql to update multiple fields at the same time, including select query

Wrong attempts:

update table name set (field 1, field 2, field 3, ...) = (select value 1, value 2, value 3, ...) where condition

Correct way:

# UPDATE OldData o, NewData n without using select 
SET o.name = n.name, o.address = n.address 
where n.nid=234 and o.id=123;

# Using select situation UPDATE OldData o, (select name, address from NewData where id = 123) n 
SET o.name = n.name, o.address = n.address 
where n.nid=234;

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Non-standard implementation code for MySQL UPDATE statement
  • mysql update case update field value is not fixed operation
  • MySQL select results to perform update example tutorial
  • Will Update in a Mysql transaction lock the table?
  • Detailed analysis of the syntax of Mysql update to modify multiple fields and
  • Record a pitfall of MySQL update statement update
  • Detailed example of MySQL joint table update data
  • Detailed explanation of the execution process of mysql update statement
  • Summary of Mysql update multi-table joint update method
  • Difference between MySQL update set and and

<<:  15 lines of CSS code can cause Apple devices to crash, and the latest iOS 12 is not immune

>>:  How to enable remote access in Docker

Recommend

Summary of the 10 most frequently asked questions in Linux interviews

Preface If you are going to interview for a Linux...

Detailed explanation of MySQL's Seconds_Behind_Master

Table of contents Seconds_Behind_Master Original ...

Use docker to build kong cluster operation

It is very simple to build a kong cluster under t...

Solve the problem of MySql client exiting in seconds (my.ini not found)

Problem description (environment: windows7, MySql...

Vue3+el-table realizes row and column conversion

Table of contents Row-Column Conversion Analyze t...

Conflict resolution when marquee and flash coexist in a page

The main symptom of the conflict is that the FLASH...

js canvas implements verification code and obtains verification code function

This article example shares the specific code of ...

Implementation of HTML sliding floating ball menu effect

CSS Styles html,body{ width: 100%; height: 100%; ...

JavaScript programming through Matlab centroid algorithm positioning learning

Table of contents Matlab Centroid Algorithm As a ...

Solve the problem after adding --subnet to Docker network Create

After adding –subnet to Docker network Create, us...

Detailed explanation of Angular structural directive modules and styles

Table of contents 1. Structural instructions Modu...

js simple and crude publish and subscribe sample code

What is Publish/Subscribe? Let me give you an exa...

Detailed explanation of how to use Vue to load weather components

This article shares with you how to use Vue to lo...