Problem with select UNION ALL mysql

Asked

Viewed 270 times

0

Galera mounted the following select in MYSQL:

                SELECT 
            id_produto, 
            SUM(qtd) as qtd 
        FROM 
         (
             SELECT 
                id, 
                id_produto, 
                qtd 
            FROM 
                produtos_pedidos 
            WHERE
                id_pedido = '1'
       UNION ALL
            SELECT 
                id, 
                id_produto, 
                qtd 
            FROM 
                pedidos_barganha
            WHERE
                id_pedido = '1'
                and tipo = 'b'
        ) res
        GROUP BY 
            id_produto 

I run it on PHPMYADMIN and it works, but it’s giving some errors in the editor, and I don’t know what it might be.

I’ll post the pictures here: inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • Which editor you are using?

  • @Carla phpmyadmin

  • have you tried another http://sqlfiddle.com/#! 2 editor? see if it helps

1 answer

1

I recommend updating the editor. This syntax is valid and you said it works if you run it in Phpmyadmin. I also suggest trying to run directly through the Mysql client. It may be that the editor you are using does not make the proper Parsing of queries, so for the editor it is wrong, but for Mysql it is not.

To handle database, I recommend Squirrel SQL.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.