MySQL Forums
Forum List  »  Spanish

Re: recuperar datos de 2 tablas
Posted by: Jorge Luis Borlando
Date: May 04, 2015 02:49PM

Jesús, gracias por tu paciencia

partamos del siguiente ejemplo

t1 tiene los siguientes valores....
1 FULANO
2 MEGANO
3 SULTANO

t2 solamente con el siguiente valor
1 40 2015-01-01

y quiero obtener el siguiente resultado
1,FULANO,2015-01-01
2.MENGANO,null (porque no existe en t2)
3,SULTANO,null (porque no existe en t2)


cuando ejecuto
SELECT t1.copro,t1.nombre,t2.fecha FROM t1
LEFT JOIN t2 ON ( t2.codpro = t1.codpro )
WHERE t2.codcli = 40

el resultado es
1,FULANO,2015-01-01,
mengano y sultano no los muestra porque no existe t2.codpro = 2 y 3

a mi entender, debería poder validar por verdadero cuando t1.codpro no exista en t2
quizás sean 2 consulta select, una para lo verdadero y otra para lo falso, validadas por un UNION, que te perece ?


saludos

Options: ReplyQuote


Subject
Views
Written By
Posted
2427
April 27, 2015 09:56AM
Re: recuperar datos de 2 tablas
1126
May 04, 2015 02:49PM


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.