主表T1,细表T2
select distinct banji_id,banji_nm from t1 where t1.banji_id in (select banji_id from T2 where T2.xuesheng_nm in ('张三','李四'))

解决方案 »

  1.   

    主表T1,细表T2
    select distinct banji_id,banji_nm from t1 where t1.banji_id in (select banji_id from T2 where T2.xuesheng_nm in ('张三','李四'))
    这语句效率不高啊!还不如exists 效率高呢,有没有别的啊!
      

  2.   

    select a.classnm
    from tmp_class a
    where exists ( select 1 from tmp_stu b
    where a.classid = b.classid
    and (stunm = 'zhang' or stunm = 'li'))