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?
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?
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
.