SELECT b.banners_id,
b.banners_title,
b.banners_text,
b.banners_url,
b.banners_image,
b.banners_group,
b.status,
date_format(b.date_scheduled, '%Y%m%d') as date_scheduled,
date_format(b.expires_date, '%Y%m%d') as expires_date,
b.max_shows,
b.max_clicks,
b.new_window,
b.date_status_change,
c.parent_id as cpid,
c.categories_id as c_id,
cc.categories_id as cc_id,
ccc.categories_id as ccc_id
FROM (banners b INNER JOIN banners_to b2
ON b.banners_id = b2.banners_id)
LEFT JOIN categories c
ON (b2.banners_to_id = c.parent_id)
LEFT JOIN categories cc
ON (c.categories_id = cc.parent_id)
LEFT JOIN categories ccc
ON (cc.categories_id = ccc.parent_id)
LEFT JOIN manufacturers m
ON (b2.banners_to_id = m.manufacturers_id)
LEFT JOIN products p
ON ( p.products_id = '38689' )
WHERE b.status = '1' AND
b.banners_place = 'top' AND
(
(
b2.banners_to_type = '' AND
( ( b2.banners_to_type = 'b' AND
( m.manufacturers_nID = '0' OR b2.banners_to_id = 0 OR b2.banners_to_id = '0')
) OR
...
Читать дальше »