SELECT * FROM (
						SELECT 
							p.product_id, 
							ps.price AS special,
							@product_rank := IF(@current_category_id = ptc.category_id, @product_rank + 1, 1) as rank,
							@current_category_id := ptc.category_id as current_category_id
						FROM oc_product_to_category ptc
						JOIN oc_product p ON p.product_id = ptc.product_id
						JOIN oc_product_special ps ON p.product_id = ps.product_id
						JOIN (SELECT @product_rank := 0, @current_category_id := NULL) as vars WHERE p.status = 1 AND p.quantity > 0 AND category_id IN (2146,2455,4043) 
						ORDER BY RAND()
						) AS x WHERE rank <= 4

						UNION

						SELECT * FROM (
							SELECT 
								p.product_id, 
								ps.price AS special,
								@product_rank := IF(@current_category_id = ptc.category_id, @product_rank + 1, 1) as rank,
								@current_category_id := ptc.category_id as current_category_id
							FROM oc_product_to_category ptc
							JOIN oc_product p ON p.product_id = ptc.product_id 
							JOIN oc_product_special ps ON p.product_id = ps.product_id
							JOIN (SELECT @product_rank := 0, @current_category_id := NULL) as vars WHERE p.status = 1 AND p.quantity > 0 AND category_id IN (2146,2455,4043)  
						ORDER BY RAND()
					) AS x WHERE rank > 2 LIMIT 0, 7