SELECT COUNT(xcart_products.productid) FROM xcart_products LEFT JOIN xcart_quick_flags ON xcart_quick_flags.productid = xcart_products.productid LEFT JOIN xcart_product_features ON xcart_product_features.productid = xcart_products.productid LEFT JOIN xcart_feature_classes ON xcart_feature_classes.fclassid = xcart_product_features.fclassid AND xcart_feature_classes.avail = 'Y' LEFT JOIN xcart_product_memberships ON xcart_product_memberships.productid = xcart_products.productid INNER JOIN xcart_featured_products ON xcart_products.productid=xcart_featured_products.productid AND xcart_featured_products.avail='Y' AND xcart_featured_products.categoryid='0' INNER JOIN xcart_quick_prices ON xcart_quick_prices.productid = xcart_products.productid AND xcart_quick_prices.membershipid = '0' LEFT JOIN xcart_variants ON xcart_variants.productid = xcart_products.productid AND xcart_quick_prices.variantid = xcart_variants.variantid INNER JOIN xcart_products_categories ON xcart_products_categories.productid = xcart_products.productid INNER JOIN xcart_categories ON xcart_products_categories.categoryid = xcart_categories.categoryid LEFT JOIN xcart_category_memberships ON xcart_category_memberships.categoryid = xcart_categories.categoryid WHERE xcart_category_memberships.membershipid IS NULL AND xcart_product_memberships.membershipid IS NULL AND xcart_categories.avail = 'Y' AND (xcart_products.forsale = 'Y' OR xcart_products.forsale = '') GROUP BY xcart_products.productid ORDER BY xcart_featured_products.product_order, xcart_products.productcode ASC, xcart_products.product ASC, xcart_products.productid ASC