现在我的oracle有2个数据表,一个A表,B表,A表:工号,日期 如:001,2011-03-15;001,2011-03-15;002,2011-04-04 总共有45条数据
B表:工号,注册日期 如:001,2011-5-3 18:02:29;001,2011-5-3 18:03:29  总共有3000多条数据
select t.ge_id,t.create_date,t1.empid,t1.date
  from A t, B t1
 where t.ge_empid(+) = t1.empid
 and to_char(t.create_date, 'YYYY-MM-DD')=t1.date不知为什么,这样查询出来有68条数据,
我想要的是准确得查询出A表里有的45条数据,且带着B表的相关信息,请问应该怎么写?

解决方案 »

  1.   

    --试试
    select t.ge_id,t.create_date,t1.empid,t1.date
      from A t, B t1
     where t.ge_empid(+) = t1.empid
     and to_char(t.create_date(+), 'YYYY-MM-DD')=t1.date
    --或者
    select t.ge_id,t.create_date,t1.empid,t1.date
      from A t right join B t1 on (t.ge_empid = t1.empid
     and to_char(t.create_date, 'YYYY-MM-DD')=t1.date)
      

  2.   

    之前 and to_char(t.create_date(+), 'YYYY-MM-DD')=t1.date 也试过,但出来的记录条数是77条,还是不是45条
      

  3.   

    应该是b表中有重复数据select t.ge_id,t.create_date,t1.empid,t1.date
      from A t, (SELECT DISTINCT empid, DATE FROM  B) t1
     where t.ge_empid = t1.empid(+)
     and to_char(t.create_date, 'YYYY-MM-DD')=t1.date(+)
      

  4.   

    tang 哥,问下这里的字段后面有(+)是啥意思?