New tables require the original table of data, mysql how to query the results into a new table

 Project application scenarios: New data tables need the original table

1. If two same tables (export and destination tables) field, and want to insert all data, this method can be used:

INSERT INTO target table SELECT * FROM source table;

For example, insertion articles table want to newArticles table, SQL statement can be achieved by:

INSERT INTO  newArticles  SELECT  * FROM  articles ;

2. If you only want to import a specified field, this method can be used:

INSERT INTO target table (Field 1, Field 2, ...) SELECT field 1, field 2, ... FROM table origin;  Note followed without parentheses

Please note that the above two fields of the table must use the same data conversion error.

3. Project application: shjz_sjzhk_da for the new file table, sr_main_da to the original master file table table, shjz_sjzhk_da save some fields sr_main_da table.

INSERT INTO shjz_sjzhk_da (
pk_sr_main,
sjbfyzj,
sjbfnf,
sjbfyf,
qhmc,
xzqh,
mhz,
mhzsfz,
mdjlx,
mxsrs,
mzjzje,
mjzksrq,
sys_xzqh,
sys_scbj
) SELECT
pk_sr_main,
sjbfyzj,
sjbfnf,
sjbfyf,
qhmc,
xzqh,
mhz,
mhzsfz,
mdjlx,
mxsrs,
mzjzje,
mjzksrq,
sys_xzqh,
sys_scbj
FROM
sr_main_da
WHERE
mhzsfz = '332627196510082957';

Guess you like

Origin www.cnblogs.com/tongcc/p/11387504.html