select emid from hrinfo where emid in('1001',1002)

解决方案 »

  1.   

    to  netcoder,不是‘或’必须是‘与’
      

  2.   

    看错了,抱歉
    select emid from cerinfo where cerid  in('1001',1002)
      

  3.   

    你这样查出来得是有1001和1002证书得所有人,一个emid可能对应多个cerid要查得是同时有1001和1002 cerid得人
      

  4.   

    select emid from hrinfo a
    where exists (select * from cerid  in('1001','1002') and a.emid =emid )
      

  5.   

    to caiyunxia,你这样查出来得还是有1001和1002证书得人,而不是同时具有1001和1002证书得人
      

  6.   

    SELECT *
    FROM hrinfo
    WHERE EXISTS (select 1 from cerinfo where cerid = '1001' and emid = hrinfo.empid)
    and EXISTS (select 1 from cerinfo where cerid = '1002' and emid = hrinfo.empid)
      

  7.   


    create table hrinfo(emid varchar(10) not null,name varchar(20))
    create table cerinfo(emid varchar(10) not null,cerid varchar(10))select a.emid,a.name 
    from hrinfo a left join cerinfo b on a.emid=b.emid
    where b.cerid='1001' or b.cerid='1002'
      

  8.   

    to playyuer,从效率上看,跟我得实现方法差不多。难道没有更简单得方法了嘛?
      

  9.   

    select empid ,count(cerid) from cerid group by empid having count(cerid)>=2;
      

  10.   

    下面的这个效率比你的快
    select emid from (select * from cerinfo where cerid='1001')  as temp where emid in (select emid from cerinfo where cerid='1002')
      

  11.   

    select * from hrinfo inner join cerinfo on cerinfo.empid=hrinfo.empid  where  creid in ('10001', '10002') 
      

  12.   

    (SELECT emid FROM cerinfo WHERE cerid = '1001') UNIOIN
    (SELECT emid FROM cerinfo WHERE cerid = '2002')