select distinct
a.EmployeeCode , a.EmployeeName, , a.Retirement_day b.Belong2Name ,
c.Belong3Name, d.Storename
from
a ,b ,c ,d , f
where
a.EmployeeManagementID = f.EmployeeManagementID
and c.Belong3Code=f.Division
and b.Belong2Code=f.Belonging
and d.Storecode=f.Store
and a.Retirement_day= '2007-04-30 00:00:00.000 '
麻烦帮我看下这个该怎么改阿? 其中:a.EmployeeCode , a.EmployeeName, , a.Retirement_day 这三个必须查出来,其他三个b.Belong2Name , c.Belong3Name, d.Storename
可能为空,现在这个语句出不出空的,要所有项都有数据的才能查出来,急啊
帮我看下怎莫改?
------解决方案--------------------
select distinct
a.EmployeeCode , a.EmployeeName, , a.Retirement_day b.Belong2Name ,
c.Belong3Name, d.Storename
from
a
left join f on a.EmployeeManagementID = f.EmployeeManagementID
left join b on b.Belong2Code=f.Belonging
left join c on c.Belong3Code=f.Division
left join d on d.Storecode=f.Store
wher
and a.Retirement_day= '2007-04-30 00:00:00.000 '
------解决方案--------------------
from
a ,b ,c ,d , f
相当于 from a inner join b on
inner join c on ...
应改成Left Join
----------------------------------
Select Distinct
a.EmployeeCode,a.EmployeeName,a.Retirement_day,b.Belong2Name,
c.Belong3Name,d.Storename
From
a
Left Join f
On a.EmployeeManagementID = f.EmployeeManagementID
Left Join c
On c.Belong3Code=f.Division
Left Join b
On b.Belong2Code=f.Belonging
Left Join d
On d.Storecode=f.Store
Where a.Retirement_day= '2007-04-30 00:00:00.000 '