数据库:MYSQL 5.0我有一语句,两个字段现在要in相同的子查询,如:select * from Table1 where field1 in (select id from A where ....) or field2 in ((select id from A where ....))怎么写最好?这样写的话是不是性能很低,子查询会进行再次查询?

解决方案 »

  1.   

    我汗...那还得学习下join怎么写,有点晕啊.像on,好像跟where差不多吧...但是它们怎么又会同时出现?
      

  2.   

    select a1.* from t1 a1 inner join a on 
    (f1=a.id or f2=a.id.....)
      

  3.   

    请问wwwwb大侠, a从哪来?是我的子查询吗?
      

  4.   

    A是你的表,即
    Select id from A where ....
      

  5.   

    看了下,我现在实际的查询是这样的select * from table where create_time = @createtime and fid in (select fid from othertable where addr in ('[email protected]','[email protected]'))其中子查询里面还有个in,in里面的条件是给死的.这样的句子可以用join代替的吗?
      

  6.   

    select * from table a1 inner join othertable b1
    on a1.fid=b1.fid
    where create_time = @createtime and b1.addr in ('[email protected]','[email protected]')
      

  7.   

    噢.不对,还有个遗留的..要加个字段条件elect * from table where create_time = @createtime and fid in (select fid from othertable where addr in ('[email protected]','[email protected]')) or  parentid in (select fid from othertable where addr in ('[email protected]','[email protected]')) 
      

  8.   

    我这样改了下不知对否
    select * from table a1 inner join othertable b1 
    on (a1.fid=b1.fid or a1.parentid = b1.fid)
    where create_time = @createtime and b1.addr in ('[email protected]','[email protected]')