MYSQL error syntax near LIMIT 0, 25

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'

11

1 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 table2

If you run in the console, you will find no problems.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like