MySQL - How to get the name of the table where the result came from? [duplicate]

1

I have the following code in mysql:

(SELECT * FROM entrada WHERE idUsuario = "1") UNION 
(SELECT * FROM saida WHERE idUsuario = "1")

It's all working but I need to know which of the 2 tables came the result, how do I do it?

    
asked by anonymous 09.02.2017 / 03:12

1 answer

4

You can try:

(SELECT 'entrada' as tipo, entrada.* FROM entrada WHERE idUsuario = "1") UNION 
(SELECT 'saida' as tipo, saida.* FROM saida WHERE idUsuario = "1")

So in each record there will be a tipo column with the value entrada or saida .

    
09.02.2017 / 03:19