MySQL Forums
Forum List  »  Spanish

Unir dos tablas y sus columnas
Posted by: Stella Funky
Date: September 09, 2013 12:04PM

Hola a todos,
Quisiera que me puedan ayudar, tengo 2 tablas que necesito unirlas, pero no todos los datos de una están en la otra y viceversa, pero aun así se deben de mostrar.

/*** tabla 1***/
select dpp.idProducto, sum(dpp.cantProducto)
from detalle_proforma_producto dpp
where dpp.idProforma in (select p.idProforma from proforma p where p.cod_empleado = '1')
group by dpp.idProducto

idProducto | sum(dpp.cantProducto)
-----------------------------------
1 |16
2 |18
3 |17
5 |3

/*** tabla 2 ***/
select die.idProducto, sum(die.cantidad)
from detalle_inv_emp die
where die.codInvEmp in (select ie.codInvEmp from inv_emp ie where ie.cod_empleado = '1')
group by die.idProducto

idProducto | sum(die.cantidad)
-----------------------------------
1 |1
2 |2
3 |1
4 |1

Pero si le aplico UNION muestra todo pero uno debajo del otro pero quisiera que se muestre en otra columna.
idProducto | sum(dpp.cantProducto)|sum(die.cantidad)
---------------------------------------------------
1 |16 |1
2 |18 |2
3 |17 |1
4 |null |1
5 |3 |null

Agredecere mucho su apoyo =D

Options: ReplyQuote


Subject
Views
Written By
Posted
Unir dos tablas y sus columnas
8687
September 09, 2013 12:04PM
1855
September 09, 2013 02:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.