SQL Server left join not giving correct result -
good day,
i have read of other problems people facing left joins, not giving correct result , maybe not understanding answers well.
here problem having on query
select ta.column1 ,d.column2 ,d.column3 ,ta.column4 ,mi.[column5] ,mi.[column6] ,d.[column7] ,d.[column8] ,ta.[column9] ,ta.[column10] ,uc.[column11] ,uc.[column12] ,ta.[column13] ,ta.[column14] ,ta.[column15] ,ta.[column16] ,ta.[column17] ,'0' column18 ,ta.[column19] ,'12.2' column20 ,'none' column21 ,'0' column22 ,'1' column23 ,ta.[column24] ,'0' column25 ,'0' column26 ,ld.column27 [db].[dbo].[table1] ta (nolock) full outer join [db].[dbo].[table2] ld (nolock) on ta.[coulmn1]=ld.[coulmn5] inner join [db].[dbo].[table3] mi (nolock) on ta.coulmn10 = mi.[coulmn3] left join [db].[dbo].[table4] d (nolock) on ta.coulmn25 = d.coulmn1 inner join [db1].[dbo].[table5] uc (nolock) on ta.coulmn12 = uc.coulmn3 (ld.coulmn5 != ta.[coulmn1]) , (ta.[coulmn23]= '0')
the problem when update query , remove
full outer join [db].[dbo].[table2] ld (nolock) on ta.[coulmn1]=ld.[coulmn5]
as remove following clause:
(ld.coulmn5 != ta.[coulmn1]) ,
i have 3 results in view on right table. correct 1 result has not been written left table
when put left outer join , clause see 2 results again, should there not 3 results last column ,ld.column27
showing null
. column accept not null
reason not getting prefered result?
use left outer join
instead of full outer join
, remove `where (ld.coulmn5 != ta.coulmn1]) and' part
try this:
select ta.column1 ,d.column2 ,d.column3 ,ta.column4 ,mi.[column5] ,mi.[column6] ,d.[column7] ,d.[column8] ,ta.[column9] ,ta.[column10] ,uc.[column11] ,uc.[column12] ,ta.[column13] ,ta.[column14] ,ta.[column15] ,ta.[column16] ,ta.[column17] ,'0' column18 ,ta.[column19] ,'12.2' column20 ,'none' column21 ,'0' column22 ,'1' column23 ,ta.[column24] ,'0' column25 ,'0' column26 ,ld.column27 [db].[dbo].[table1] ta (nolock) left outer join [db].[dbo].[table2] ld (nolock) on ta.[coulmn1]=ld.[coulmn5] inner join [db].[dbo].[table3] mi (nolock) on ta.coulmn10 = mi.[coulmn3] left join [db].[dbo].[table4] d (nolock) on ta.coulmn25 = d.coulmn1 inner join [db1].[dbo].[table5] uc (nolock) on ta.coulmn12 = uc.coulmn3 (ta.[coulmn23]= '0')
Comments
Post a Comment