MySQL Field Copy Before Different Tables

  • 2021-11-24 03:08:28
  • OfStack

Sometimes, we need to copy the whole column of data from one field 1 to another new field. This is very simple. SQL can be written as follows:

UPDATE tb_1 SET content_target = content_source;

It is roughly written as follows:

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

Navicat and other tools are better, you can directly select 1 column of data, copy and paste into the column you need. If it is the same table, it is no problem. If it is a new table, please keep the number of rows to be 1. If the number of rows is not 1, you can create a new table and copy the columns in, so that the number of id will remain 1.

Sometimes these MySQL interface tools will report errors, so it is better to use the command line at this time. For example, if you copy the data from one table field to another table field, you can write as follows:

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

Here is a practical example of writing a link to a static page that PHPCMS has generated to the url field in the phpcms_content table:

Piece together the required url field columns in this way.

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 copy to the url column in the phpcms_content table.


Related articles: