Home > Database > Mysql Tutorial > body text

How to copy MySQL table fields to another table field

怪我咯
Release: 2017-04-10 09:29:02
Original
2667 people have browsed it

Sometimes, we need to copy an entire column of data in a certain field to another new field. This is very simple. SQL can be written like this:

UPDATE tb_1 SET content_target = content_source;
Copy after login

It can be written as follows:

Update {your_table} set {source_field} = {object_field} WHERE cause
Copy after login

It is better to have tools such as Navicat. You 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 their 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 this case, it is better to use the command line. For example, to copy one table field data 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
Copy after login

The following is a practical example, writing 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 columns like this.

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

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

The above is the detailed content of How to copy MySQL table fields to another table field. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template