Mysql
 sql >> Database >  >> RDS >> Mysql

inserire tutte le righe dalla tabella in un'altra tabella, singola query

Dai un'occhiata a

INSERT ... SELECT Sintassi

Sintassi

INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name [(col_name,...)]
    SELECT ...
    [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]

Esempio

INSERT INTO tbl_temp2 (fld_id)
  SELECT tbl_temp1.fld_order_id
  FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

DEMO SQL Fiddle