有表TABLE1和TABLE2
TABLE1中有字段ID(自动累加),ClassID(字符类型),otherA(字符类型)
TABLE2中有字段ID(自动累加),ClassID(字符类型),otherB(字符类型)
今需要查询一些TABLE1中的数据,而这些TABLE1中的数据的TABLE1.ClassID的值是和在表Table2中所有TABLE2.otherB=‘aaa’的数据的TABLE2.ClassID相等的数据,应如何写SQL语句来查询TABLE1中的这些数据?
TABLE1中有字段ID(自动累加),ClassID(字符类型),otherA(字符类型)
TABLE2中有字段ID(自动累加),ClassID(字符类型),otherB(字符类型)
今需要查询一些TABLE1中的数据,而这些TABLE1中的数据的TABLE1.ClassID的值是和在表Table2中所有TABLE2.otherB=‘aaa’的数据的TABLE2.ClassID相等的数据,应如何写SQL语句来查询TABLE1中的这些数据?
SQL codeselect * from table1 where classid in(select classid from table2 where otherb='aaa')
=======================================谢谢
那现在我想在这个查询结果的基础上加一个条件:table1.otherA='bbb'请问,又该如何做?
table1 a,table b
where a.classid=b.classid
and b.otherb='aaa'
where classid in(select classid from table2 where otherb='aaa') and
table1.otherA='bbb'
table1 a,table b
where a.classid=b.classid
and a.othera='bbb' and b.otherb='aaa'