2012年2月26日星期日

full outer join

hello
i know that this post is not related to asp.net forum but if anyone can help me.
i have made three sql tables called table1,table2 and table3.
each one contains primary field called employeeid
table1 contains in addition to the primary a field callled field1.
table2 contains in addition to the primary a field callled field2.
table3 contains in addition to the primary a field callled field3.
the first time table1 contains one record
employeeid field1
---- --
1353 abc
the second table contains no data
the third table contains also one record
employeeid field3
---- --
1353 def
i have made a query :
select field1,field2,field3 from table1
full outer join table2 on table1.employeeid=table2.employeeid
full outer join table3 on table2.employeeid=table3.employeeid
the result is :
field1 field2 field3
abc null null
null null def
when i delete the record from the first table and put it in the second empty table:
the result :
field1 field2 field3
null abc def
i need to understand the results ?
i know that the outer join will get the rows from the both tables,but the results how can i get i don't understand
thank you for the help

The results you are getting is because OUTER JOIN defaults mathematically to a NULL so you need to use the ISNULL function with your replacement value. And I cannot remember now but OUTER JOIN have fixed table placement in the query to get expected results. BTW strange things happening with OUTER JOIN is normal. Hope this helps.

没有评论:

发表评论