为什么UNION ALL不工作?

时间:2017-11-01 17:40:22

标签: mysql

我创建了一个查询,将一个表的数据传递给另一个表但返回错误:

  

Símbolo(令牌)inesperado。 (位置150处的“UNION ALL”附近)

这里是我的查询:

insert into vencimientos_arba(impuestoId, impuesto, vencimiento)
select id, concepto, CONCAT('2017-', anticipo1) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo2) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo3) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo4) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo5) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo6) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo7) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo8) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo9) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo10) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, CONCAT('2017-', anticipo11) AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, anticipo12 AS concatenar from ingresos_brutos
UNION ALL
select id, concepto, anual AS concatenar from ingresos_brutos
ORDER BY id ASC

1 个答案:

答案 0 :(得分:4)

与其他一些数据库引擎不同,在MySQL中,我们需要将VALUES关键字与INSERT INTOSELECT一起使用:

INSERT INTO table (columns) VALUES
SELECT columns FROM table
 UNION ALL 
SELECT columns FROM table
...

这就是我们在问题中看到“意外令牌”错误的原因。