select name from table1 A where 
exists (select * from table2 B where A.id = B.id)
uion all 
 select ‘’ from table1 A where 
not exists (select * from table2 B where A.id = B.id)

解决方案 »

  1.   

    select isnull(表1.NAME,表2.id) AS ID  from 表2 left join 表1 on 表2.id=表1.id
      

  2.   

    如果有3个表呢?
    表1   ID    NAME        表2   ID                 表3   ID   NAME
                1     A           1                         3    C
                2     B          ‘’                      
    有一条记录为:
                        1     3   ‘’
    我想取出来的时候是:A     C   ‘’
      

  3.   

    select CONVERT(varchar(10),a.ReportDate,126) as 日志日期,CONVERT(varchar(8),a.WorkTimeFrom,114) as 工作开始时间,CONVERT(varchar(8),a.WorkTimeTo,114) as 工作结束时间,a.ProID as 项目编号,
    isnull(b.ActionName,a.actionsecondid) as 当前动作,isnull(c.ActionName,a.actionsecondid) as 特殊描述,a.WorkDesc2 as 工作描述2,a.WorkDesc3 as 工作描述3 
    from  tabPersonReport a
    left join tabPersonAction b, tabJapanAction c on (a.ActionSecondID=b.ActionSecondID and  a.workdesc1= c.ActionSecondID) AND a.employeeid='02091'
    请帮我看看这句句子哪里有错?
      

  4.   

    select CONVERT(varchar(10),a.ReportDate,126) as 日志日期,CONVERT(varchar(8),a.WorkTimeFrom,114) as 工作开始时间,CONVERT(varchar(8),a.WorkTimeTo,114) as 工作结束时间,a.ProID as 项目编号,
    isnull(b.ActionName,a.actionsecondid) as 当前动作,isnull(c.ActionName,a.actionsecondid) as 特殊描述,a.WorkDesc2 as 工作描述2,a.WorkDesc3 as 工作描述3 
    from  tabPersonReport a
    left join tabPersonAction b on a.ActionSecondID=b.ActionSecondID
    left join tabJapanAction c on  a.workdesc1= c.ActionSecondID
    where a.employeeid='02091'
      

  5.   

    这句查询语句在SQL查询分析器里报错啊!错误为:
    服务器: 消息 208,级别 16,状态 1,行 1
    对象名 'tabPersonReport' 无效。
    服务器: 消息 208,级别 16,状态 1,行 1
    对象名 'tabPersonAction' 无效。
    服务器: 消息 208,级别 16,状态 1,行 1
    对象名 'tabJapanAction' 无效。