SELECT b.module,b.page,b.place,b.priority,b.rate,b.banner_id,b.text_id,b.type,b.html,b.direct_link,b.url,b.url_target,b.width,b.height FROM banners b INNER JOIN banner_types t ON b.place=t.place WHERE (b.module='9' OR b.module IS NULL) AND (b.page='34' OR b.page IS NULL) AND ((b.need='clicks' and b.clicked < b.show_click) or (b.need='hits' and b.showed < b.show_click) or b.need='always' or b.html!='') AND b.rate!=0 GROUP BY b.banner_id ORDER BY b.priority