我是用的这条sql语句,但出现很多重复记录,如下:
select a.schoolname ,a.address ,a.telephone a.photo from 表1 a,表2 b where a.schoolid=b.schoolid and a.provin=1 and a.city=1 and b.catname='关键词'
求关于两表联合查询的sql2005 最优化语句?
------解决方案--------------------
我上面已经修改了代码,使用exists了哈,用join肯定是会导致重复的:
select t1.schoolname,t1.address,t1.telephone,t1.photo
from 表1 t1
where t1.provin=1 and t1.city=1
and exists(select 1 from 表2 t2
where t1.schoolid = t2.schoolid and t2.catname='xxx')