数据库:MYSQL 5.0我有一语句,两个字段现在要in相同的子查询,如:select * from Table1 where field1 in (select id from A where ....) or field2 in ((select id from A where ....))怎么写最好?这样写的话是不是性能很低,子查询会进行再次查询?
select a1.* from t1 a1 inner join a on (f1=a.id or f2=a.id.....)
请问wwwwb大侠, a从哪来?是我的子查询吗?
A是你的表,即 Select id from A where ....
看了下,我现在实际的查询是这样的select * from table where create_time = @createtime and fid in (select fid from othertable where addr in ('[email protected]','[email protected]'))其中子查询里面还有个in,in里面的条件是给死的.这样的句子可以用join代替的吗?
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]')
我这样改了下不知对否 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]')
(f1=a.id or f2=a.id.....)
Select id from A where ....
on a1.fid=b1.fid
where create_time = @createtime and b1.addr in ('[email protected]','[email protected]')
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]')