SELECT p.products_has_downloads, zp2.products_id AS mp3_album_id, zp2.products_status AS mp3_album_status, zp2.products_date_available AS mp3_date_available, o.date_purchased, ra.artists_name, p.products_image, p.products_rrp, p.products_loyalty_points, op.products_id, SUM(op.products_quantity), COUNT(p.products_id), pd.products_name, SUM(op.products_quantity)
FROM
zen_products p LEFT JOIN zen_products zp2 ON zp2.parent_product_id = p.products_id,
zen_orders_products op, zen_orders o, zen_products_description pd,
zen_product_music_extra me, zen_record_artists ra, zen_products_to_categories p2c
WHERE o.date_purchased > 20130321
AND (o.date_purchased < '2013-02-26 00:00:00' OR o.date_purchased> '2013-03-12 23:59:59')
AND o.orders_id = op.orders_id
AND me.products_id = op.products_id
AND me.products_id = p.products_id
and p.products_statustext != 'Discontinued'
and p.products_status = 1
and p.products_type != 7 and p.products_type != 8 and p.products_type != 9
AND op.products_id = pd.products_id
AND p2c.products_id = op.products_id
AND (zp2.products_type = 7 or zp2.products_type is null)
AND me.artists_id = ra.artists_id AND ( p2c.categories_id=5 OR p2c.categories_id=21 OR p2c.categories_id=24 OR p2c.categories_id=25 OR p2c.categories_id=26 OR p2c.categories_id=27 OR p2c.categories_id=28 OR p2c.categories_id=29 OR p2c.categories_id=30 OR p2c.categories_id=31 OR p2c.categories_id=32 OR p2c.categories_id=33 OR p2c.categories_id=34 OR p2c.categories_id=35 OR p2c.categories_id=36 OR p2c.categories_id=37 OR p2c.categories_id=38 OR p2c.categories_id=39 OR p2c.categories_id=40 OR p2c.categories_id=41 OR p2c.categories_id=42 OR p2c.categories_id=43 OR p2c.categories_id=44 OR p2c.categories_id=45 OR p2c.categories_id=46 OR p2c.categories_id=47 OR p2c.categories_id=48 OR p2c.categories_id=49 OR p2c.categories_id=50 OR p2c.categories_id=51 OR p2c.categories_id=52 OR p2c.categories_id=53 OR p2c.categories_id=54 OR p2c.categories_id=55 OR p2c.categories_id=56 OR p2c.categories_id=57 OR p2c.categories_id=58 OR p2c.categories_id=59 OR p2c.categories_id=60 OR p2c.categories_id=61 OR p2c.categories_id=62 OR p2c.categories_id=63 OR p2c.categories_id=64 OR p2c.categories_id=65 OR p2c.categories_id=66 OR p2c.categories_id=67 OR p2c.categories_id=68 OR p2c.categories_id=69 OR p2c.categories_id=70 OR p2c.categories_id=71 OR p2c.categories_id=72 OR p2c.categories_id=73 OR p2c.categories_id=74 OR p2c.categories_id=75 OR p2c.categories_id=76 OR p2c.categories_id=77 OR p2c.categories_id=79 OR p2c.categories_id=80 OR p2c.categories_id=81 OR p2c.categories_id=82 OR p2c.categories_id=83 OR p2c.categories_id=84 OR p2c.categories_id=85 OR p2c.categories_id=86 OR p2c.categories_id=87 OR p2c.categories_id=88 OR p2c.categories_id=89 OR p2c.categories_id=90 OR p2c.categories_id=91 OR p2c.categories_id=92 OR p2c.categories_id=93 OR p2c.categories_id=94 OR p2c.categories_id=95 OR p2c.categories_id=96 OR p2c.categories_id=97 OR p2c.categories_id=98 OR p2c.categories_id=99 OR p2c.categories_id=100 )
GROUP BY products_id
ORDER BY SUM(op.products_quantity) DESC
LIMIT 12
12
select p.products_date_available as date_expected, p.products_has_downloads, zp2.products_id AS mp3_album_id,p.products_type, zp2.products_status AS mp3_album_status, zp2.products_date_available AS mp3_date_available, p.products_importance_europe, p.products_date_available, p.products_loyalty_points, p.products_id, p.products_image, p.products_tax_class_id, p.products_price, p.products_rrp, p.products_date_added, ra.artists_name
from (((zen_products p join zen_products_description pd on p.products_id = pd.products_id) left join zen_product_music_extra me on me.products_id = p.products_id) left join zen_record_artists ra on ra.artists_id = me.artists_id)
LEFT JOIN zen_products zp2 ON zp2.parent_product_id = p.products_id
where pd.language_id = '1'
and (zp2.products_type = 7 or zp2.products_type is null)
and p.products_id IN (20774,17086,17205,16578,16579,20780,20782,17087,20776,20783,17013,17014) GROUP BY p.products_id ORDER BY date_expected asc, p.products_importance_europe DESC