表1 mid,date(日期 例:2010-09-29)
表2 name,mid(与表1 mid存入的值相同)通过sql在表1中查询一定日期范围内的mid的值设为midList
然后利用midList查询表2中的name值为nameList要的就是最后的nameList的结果,怎么查询合理些,望高手解决?

解决方案 »

  1.   

    select t2.name from 表2 t2,
    (select * from 表1 where date='2010-09-29') t1
    where t2.mid=t1.mid
      

  2.   

    select midList=a.mid, nameList=b.name from 表1 a join 表2 b on a.mid=b.mid
    where a.date ?
      

  3.   


    select name from 表2
    where mid in
    (select distinct mid from 表1
    where date='2010-09-29')
      

  4.   


    select distinct name from 表2
    where mid in
    (select distinct mid from 表1
    where date='2010-09-29')
      

  5.   

    select  nameList=name from 表1 a  where exists (select 1 from 表2 b where a.mid=b.mid
    and a.date =....)只要一表数据这样性能更好如果要两表数据,连接查询
      

  6.   

    select  nameList=name from 表1 a  where exists (select 1 from 表2 b where a.mid=b.mid)
    and a.date =....