Copy fields between different tables in MySQL

Copy fields between different tables in MySQL

Sometimes, we need to copy a whole column of data from a field to another new field. This is very simple. The SQL can be written like this:

UPDATE tb_1 SET content_target = content_source;

The general way of writing is as follows:

Update {your_table} set {source_field} = {object_field} WHERE cause

It is better to have tools such as Navicat, which can directly select a column of data and copy and paste it into the column you need. If it is the same table, there is no problem. If it is a new table, please keep the number of rows consistent. If the number of rows is inconsistent, you can create a new table and copy the columns into it, so that the number of ids will remain consistent.

Sometimes these MySQL interface tools will report errors, in which case it is better to use the command line. For example, to copy the data of a table field to another table field, you can write:

UPDATE tb_1 INNER JOIN tb_2 ON tb_1.tid = tb_2.tid
SET tb_1.tcontent = tb_2.tcontent

The following is a practical example, which writes the link of the static page generated by PHPCMS into the url field in the phpcms_content table:

First, piece together the required URL field column.

SELECT CONCAT(FROM_UNIXTIME(inputtime,'%Y/%m%d'), '/', contentid, '.html') AS dt FROM phpcms_content ORDER BY contentid DESC

Then in the query editor (navicat), copy the entire paragraph to the url column in the phpcms_content table.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Three ways to copy MySQL tables (summary)
  • Three implementation methods of Mysql copy table and grant analysis
  • Mysql method to copy a column of data in one table to a column in another table
  • How to use worm replication in Mysql data table
  • MySQL replication table details and example code
  • How to copy MySQL query results to a new table (update, insert)
  • mysql copy table structure and data example code
  • Tutorial on copying data from a table to a new table in MySQL
  • Tutorial on table replication and large data table backup in MySQL
  • Mysql method of copying table structure and table data
  • How to copy MySQL table

<<:  A brief analysis of crontab task scheduling in Linux

>>:  Vue integrates Tencent TIM instant messaging

Recommend

How to install SVN server under Linux

1. Yum installation yum install subversion 2. Con...

Detailed process of using nginx to build a webdav file server in Ubuntu

Install nginx Note that you must install nginx-fu...

Summary of the application of transition components in Vue projects

​Transtion in vue is an animation transition enca...

Example of cross-database query in MySQL

Preface In MySQL, cross-database queries are main...

JS ES new feature of variable decoupling assignment

Table of contents 1. Decoupled assignment of arra...

Detailed explanation of Tomcat directory structure

Table of contents Directory Structure bin directo...

How to use JavaScript and CSS correctly in XHTML documents

In more and more websites, the use of XHTML is rep...

Best Practices for Implementing Simple Jira Projects with React+TS

A set of projects for training react+ts Although ...

A brief analysis of the count tracking of a request in nginx

First, let me explain the application method. The...

How to set up a shared folder on a vmware16 virtual machine

1. Set up a shared folder on the virtual machine:...

Vue implements sending emoticons in chat box

The specific code for sending emoticons in the vu...

Linux editing start, stop and restart springboot jar package script example

Preface In the springboot configuration file, the...

JS implements WeChat's "shit bombing" function

Hello everyone, I am Qiufeng. Recently, WeChat ha...