SELECT SQL_CALC_FOUND_ROWS distinct(products.PRODUCT_ID),
products.PARENT_PRODUCT_ID,
substr(products.TITLE,1,10) AS TITLE,
substr(products.AUTHOR,1,10) AS AUTHOR,
products.SALES_RANK,
products.SALES_RANK_INGRAM,
IFNULL(products.SALES_RANK, 'Z') as SALES_RANK_SORT,
products.stock_qty_sold,
products_store.store_qty_sold,
products.image_has_small as IMAGE_HAS_SMALL FROM products left join products_store on (products.product_id = products_store.product_id and products_store.store_id = 6999) , products_category_cbc WHERE products.store_id in (0, 6999) AND products.STORETYPE_ID1 = 'Y' AND cbc_super in ('RVR', 'LBL', 'NVI') AND products.product_id = products_category_cbc.product_id and products_category_cbc.cbc_sub = 'LGP' AND (products.stock_available_flag in ('Y', 'P') or release_date >= curdate()) AND (censorship_flag is null or censorship_flag <> 'Y') AND (products.PRICE > 0 or products.product_config in ('eBook', 'eBooks', 'mp3')) AND (products.STATUS in ('A', 'B', 'C', 'M')) AND ( products.product_id not in (select product_term as product_id from store_product_censor where censorship_type = 'PID' and store_product_censor.store_id = 6999) and products.isbn not in (select product_term as isbn from store_product_censor where censorship_type = 'PIS' and store_product_censor.store_id = 6999) and products.upc not in (select product_term as upc from store_product_censor where censorship_type = 'PUP' and store_product_censor.store_id = 6999) and products.ean not in (select product_term as ean from store_product_censor where censorship_type = 'PEA' and store_product_censor.store_id = 6999) and products.author not in (select product_term as author from store_product_censor where censorship_type = 'AU' and store_product_censor.store_id = 6999) and products.product_config not in (select product_term as product_config from store_product_censor where censorship_type = 'PC' and store_product_censor.store_id = 6999) and products.publisher_name not in (select product_term as publisher_name from store_product_censor where censorship_type = 'PUB' and store_product_censor.store_id = 6999) and products.publisher not in (select product_term as publisher from store_product_censor where censorship_type = 'PUC' and store_product_censor.store_id = 6999) ) ORDER BY sales_rank_ingram desc, stock_qty_sold desc, TITLE LIMIT 1000

SELECT SQL_CALC_FOUND_ROWS distinct(products.PRODUCT_ID),
products.PARENT_PRODUCT_ID,
substr(products.TITLE,1,10) AS TITLE,
substr(products.AUTHOR,1,10) AS AUTHOR,
products.SALES_RANK,
products.SALES_RANK_INGRAM,
IFNULL(products.SALES_RANK, 'Z') as SALES_RANK_SORT,
products.stock_qty_sold,
products_store.store_qty_sold,
products.image_has_small as IMAGE_HAS_SMALL FROM products left join products_store on (products.product_id = products_store.product_id and products_store.store_id = 6999) , products_category_cbc WHERE products.store_id in (0, 6999) AND products.STORETYPE_ID1 = 'Y' AND cbc_super in ('RVR', 'LBL', 'NVI') AND products.product_id = products_category_cbc.product_id and products_category_cbc.cbc_sub = 'LGP' AND (products.stock_available_flag in ('Y', 'P') or release_date >= curdate()) AND (censorship_flag is null or censorship_flag <> 'Y') AND (products.PRICE > 0 or products.product_config in ('eBook', 'eBooks', 'mp3')) AND (products.STATUS in ('A', 'B', 'C', 'M')) AND ( products.product_id not in (select product_term as product_id from store_product_censor where censorship_type = 'PID' and store_product_censor.store_id = 6999) and products.isbn not in (select product_term as isbn from store_product_censor where censorship_type = 'PIS' and store_product_censor.store_id = 6999) and products.upc not in (select product_term as upc from store_product_censor where censorship_type = 'PUP' and store_product_censor.store_id = 6999) and products.ean not in (select product_term as ean from store_product_censor where censorship_type = 'PEA' and store_product_censor.store_id = 6999) and products.author not in (select product_term as author from store_product_censor where censorship_type = 'AU' and store_product_censor.store_id = 6999) and products.product_config not in (select product_term as product_config from store_product_censor where censorship_type = 'PC' and store_product_censor.store_id = 6999) and products.publisher_name not in (select product_term as publisher_name from store_product_censor where censorship_type = 'PUB' and store_product_censor.store_id = 6999) and products.publisher not in (select product_term as publisher from store_product_censor where censorship_type = 'PUC' and store_product_censor.store_id = 6999) ) ORDER BY sales_rank_ingram desc, stock_qty_sold desc, TITLE LIMIT 1000