I have a query with this structure trying to run in PHPMYADMIN. I going crazy with this, somebody can tell me what is wrong in here?
If i run the SELECTs separately, they work just fine. When i run togheter with the union it crash.
SELECT 1 AS orden, CONCAT(profesor.nombre,' ', profesor.apellido) profesor, cobro.monto
FROM cobro INNER JOIN profesor ON cobro.idProfesor = profesor.idProfesor WHERE cobro.idEstado=9
UNION ALL
SELECT 1 AS orden, CONCAT(profesor.nombre,' ', profesor.apellido) profesor, retiro.monto
FROM retiro INNER JOIN profesor ON cobro.idProfesor = profesor.idProfesor WHERE retiro.idEstado=11
UNION ALL
SELECT 2 AS orden, 'TOTAL' profesor, SUM(monto) AS monto
FROM (SELECT monto FROM cobro UNION ALL SELECT monto FROM retiro) AS T1 MYSQL Error = #1064 - Syntax error near 'LIMIT 0, 25'
111 Answer
The query was right. The problem was Phpmyadmin that give that error when you have a query with union and a derived table like this.
SELECT field FROM table1
UNION ALL
SELECT field FROM (SELECT * FROM table) AS table2If you run in the console, you will find no problems.