select t1.siteid , t1.ownerid , t1.ownertable , t1.ftype , t1.fdocument , t1.tattachmentid , t1.postfix , t1.serialnumber , t1.fobsurl , t2.fobsurl as fobsurl_thumbnail , t3.fobsurl as fobsurl_compressed , t4.fobsurl as fobsurl_hls , t1.createdate , t1.contentlength from tattachment t1 left join tattachment t2 on t1.siteid=t2.siteid and t1.tattachmentid=t2.fparentid and t2.ftype='thumbnail' left join tattachment t3 on t1.siteid=t3.siteid and t1.tattachmentid=t3.fparentid and t3.ftype='compressed' left join tattachment t4 on t1.siteid=t4.siteid and t1.tattachmentid=t4.fparentid and t4.ftype='hls' where t1.ownertable =$ownertable$ and t1.ftype=$ftype$ and t1.siteid=$siteid$ and t1.ownerid in $ownerid$ and isnull(t1.fparentid,0)=0 order by t1.tattachmentid