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

Linux uses binary mode to install mysql

This article shares the specific steps of install...

Use SQL statement to determine whether the record already exists before insert

Table of contents Determine whether a record alre...

js canvas realizes slider verification

This article example shares the specific code of ...

Full analysis of web page elements

Relative Length Units em Description: Relative len...

Detailed explanation of how to monitor MySQL statements

Quick Reading Why do we need to monitor SQL state...

Steps to solve the MySQL 8.0 time zone problem

Software Version Windows: Windows 10 MySQL: mysql...

JavaScript code to implement a simple calculator

This article example shares the specific code of ...

The difference and reasons between the MySQL query conditions not in and in

Write a SQL first SELECT DISTINCT from_id FROM co...

Vue simple implementation of turntable lottery

This article shares the specific code of Vue to s...

MySQL's conceptual understanding of various locks

Optimistic Locking Optimistic locking is mostly i...

A brief discussion on the role of HTML empty links

Empty link: That is, there is no link with a targ...

Using JavaScript in HTML

The <script> tag In HTML5, script has the f...

Detailed explanation of Promises in JavaScript

Table of contents Basic usage of Promise: 1. Crea...

Use Rem layout to achieve adaptive

I have written an article about mobile adaptation...

Implementation of iview permission management

Table of contents iview-admin2.0 built-in permiss...