Meta Code
Meta Code

Reputation: 607

Why does not this UNION ALL work?

i create a query to pass the data of one table to other but return an error:

Símbolo (token) inesperado. (near "UNION ALL" at position 150)

here my query:

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

Upvotes: 0

Views: 826

Answers (1)

Cy Rossignol
Cy Rossignol

Reputation: 16827

Unlike some other database engines, in MySQL, we need to use the VALUES keyword with INSERT INTO and SELECT:

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

This is why we see the "unexpected token" error shown in the question.

Upvotes: 4

Related Questions