SELECT SQL_CALC_FOUND_ROWS A.* ,R.logo as R_logo,R.nazwa as R_nazwa,R.id as R_id,R.xstatus as R_xstatus,R.symbol as R_symbol,R.status as R_status,R.woj as R_woj,R.opis as R_opis , Z.woj as Z_woj, Z.powiat as Z_powiat, A.opisen as opis,RAND() random,0 as __search_priority FROM act_base_asortyment as A LEFT JOIN act_base_firmy as R ON R.id = A.firma LEFT JOIN act_base_siec as Z ON R.id = Z.firma AND Z.status = 1 WHERE ((A.menu_id = '571' OR (A.mcat9 & 1048576)) AND (R.status = 1 AND A.hide = 0 AND R.xstatus >= 1) AND A.status = 1 ) AND (A.perms & 1) AND A.lang & 4 AND A.date_end >= NOW() AND A.date_start <= NOW() GROUP BY A.id ORDER BY R.xstatus DESC, (A.foto != '') DESC, random, R.pub_time DESC, A.akolej LIMIT 0, 21