select t1.fclass1,t1.fclass2,t1.ftitle,t1.submitby,t1.submitdate,t1.fnotes,t1.fstatus,t1.tarchivesid,t1.createby,t1.createdate,t1.fvisitors,case when t2.tarchives_collecid IS null then 0 else 1 end fiscollection
from tarchives t1
left join tarchives_collection t2 on t1.siteid=t2.siteid and t1.tarchivesid=t2.tarchivesid and t2.tenterprise_userid=$tenterprise_userid$
where t1.siteid=$siteid$ and $where$
