SELECT
SQL_CALC_FOUND_ROWS products.product_id,
descr1.product as product,
companies.company as company_name,
companies.ag_hide_city as company_city_hide,
companies.city as company_city,
companies.state as company_state
FROM
products as products
LEFT JOIN product_descriptions as descr1 ON descr1.product_id = products.product_id
AND descr1.lang_code = 'en'
LEFT JOIN product_prices as prices ON prices.product_id = products.product_id
AND prices.lower_limit = 1
LEFT JOIN companies AS companies ON companies.company_id = products.company_id
INNER JOIN products_categories as products_categories ON products_categories.product_id = products.product_id
INNER JOIN categories ON categories.category_id = products_categories.category_id
AND (
categories.usergroup_ids = ''
OR FIND_IN_SET(0, categories.usergroup_ids)
OR FIND_IN_SET(1, categories.usergroup_ids)
)
AND categories.status IN ('A', 'H')
AND categories.storefront_id IN (0, 1)
LEFT JOIN product_options_inventory as inventory ON inventory.product_id = products.product_id
WHERE
1
AND companies.status IN ('A')
AND products.company_id = 9763
AND (
products.amount > 0
OR products.tracking = 'D'
)
AND products.product_id IN (0)
AND (
products.usergroup_ids = ''
OR FIND_IN_SET(0, products.usergroup_ids)
OR FIND_IN_SET(1, products.usergroup_ids)
)
AND products.status IN ('A')
AND prices.usergroup_id IN (0, 0, 1)
AND products.company_id = 9763
GROUP BY
products.product_id
ORDER BY
product asc,
products.product_id ASC
LIMIT
0, 100