select LR.FlowID,LR.StartTime,LR.EndTime,LR.DelFlag,LR.FilePath,LR.FileName,LR.resv1,LR.AppraiseFlag,LB.Phone,U.UserNo,U.Name,U.OwnErea,U.OwnLochus,
(SELECT D.dataName FROM DataDict D WHERE D.parentSerial = '4' AND D.childSerial =U.OwnErea) AS OwnEreaDict,
(select D.dataName from DataDict D where D.parentSerial = '5' and D.childSerial = U.ownlochus) as OwnlochusDict,
p.name as visitorName,p.relation
from LRecord LR,UserInfo U,LBill LB ,PhoneNo p
where U.UserNo = LR.CardNo and LB.SerialNo = LR.SerialNo and LR.ServiceNo=1 and LB.Phone = p.phone and LB.CardNo = p.UserNo我现在要加一张表GroupInfo,这张表跟UserInfo 这张表有关系.U.userNo=g.UserNo
但是这样一连接那么UserInfo里面有些数据就显示不出来,我现在想要的是把UserInfo里面的数据都显示出来,应该在我原有的代码上怎么改呢?

解决方案 »

  1.   

    select   LR.FlowID,LR.StartTime,LR.EndTime,LR.DelFlag,LR.FilePath,LR.FileName,LR.resv1,LR.AppraiseFlag,LB.Phone,U.UserNo,U.Name,U.OwnErea,U.OwnLochus, 
    (SELECT   D.dataName   FROM   DataDict   D   WHERE   D.parentSerial   =   '4'   AND   D.childSerial   =U.OwnErea)   AS   OwnEreaDict, 
    (select   D.dataName   from   DataDict   D   where   D.parentSerial   =   '5'   and   D.childSerial   =   U.ownlochus)   as   OwnlochusDict, 
    p.name   as   visitorName,p.relation ,
    g.*from   LRecord   LR inner join UserInfo   U
    on U.UserNo   =   LR.CardNo
    inner join LBill   LB   
    on LB.SerialNo   =   LR.SerialNo
    inner join PhoneNo   p 
    on  LB.Phone   =   p.phone   and   LB.CardNo   =   p.UserNo 
    left join GroupInfo g
    on U.userNo=g.UserNo
    where LR.ServiceNo=1
      

  2.   

    这样做产生了8条重复的记录,要用distinct去掉重复行?
      

  3.   


    group by LB.SerialNo