MySQL Forums
Forum List  »  General

Left Outer Join
Posted by: Wei Fan Chen
Date: May 02, 2016 09:50PM

Hi~
Big Issue in "Left Outer Join"

"mydata" table schema
pk1 as varchar , pk2 as varchar,pk3 as datatime, value1 as int,value2 as int

Left Outer Join SQL
select a.pk1,a.pk3,a.value1,a.value2,b.value1,b.value2
from mydata as a
left outer join mydata as b
on (a.pk1=b.pk1 and b.pk2='data2' and a.pk3=b.pk3)
where a.pk1='abc' and a.pk2='data1' and a.pk3>='2016/5/3 15:00' and a.pk3<='2016/5/3 16:00'

it's OK when pk3 us >= & <= , select result
abc ,2016/5/3 15:00 , 1,1,2,2
abc ,2016/5/3 15:30 , 2,2,9,9
abc ,2016/5/3 16:00 , 3,3,12,12

but when i use a.pk3='2016/5/3 15:00', select result
abc ,2016/5/3 15:00 , 1,1,null,null


i try it at MS SQL, select result
abc ,2016/5/3 15:00 , 1,1,2,2

what's the different ??? and how should i fix MySQL sql stirng ??

Options: ReplyQuote


Subject
Written By
Posted
Left Outer Join
May 02, 2016 09:50PM
May 03, 2016 03:28PM
May 05, 2016 09:38PM


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.