有表TABLE1和TABLE2
TABLE1中有字段ID(自动累加),ClassID(字符类型),otherA(字符类型)
TABLE2中有字段ID(自动累加),ClassID(字符类型),otherB(字符类型)
今需要查询一些TABLE1中的数据,而这些TABLE1中的数据的TABLE1.ClassID的值是和在表Table2中所有TABLE2.otherB=‘aaa’的数据的TABLE2.ClassID相等的数据,应如何写SQL语句来查询TABLE1中的这些数据?

解决方案 »

  1.   

    select * from table1 where classid in(select classid from table2 where otherb='aaa')
      

  2.   

    发表于:2007-12-26 17:30:371楼 得分:0 
    SQL codeselect * from table1 where classid in(select classid from table2 where otherb='aaa') 
    =======================================谢谢
    那现在我想在这个查询结果的基础上加一个条件:table1.otherA='bbb'请问,又该如何做?
      

  3.   

    select a.* from 
    table1 a,table b 
    where a.classid=b.classid
    and b.otherb='aaa'
      

  4.   

    select * from table1 
    where classid in(select classid from table2 where otherb='aaa') and
              table1.otherA='bbb'
      

  5.   

    select   a.*   from  
    table1   a,table   b  
    where   a.classid=b.classid
    and   a.othera='bbb' and b.otherb='aaa'