SELECT products.*, product_brands.brand as brandname FROM `products` LEFT JOIN product_brands ON product_brands.id = products.brand LEFT JOIN `products_sort` ON `products`.`id` = `products_sort`.`product_id` AND `products_sort`.`topic_id` = '395' WHERE products.site = '416' AND ( `hidden` = '0' ) AND ( `topics` LIKE '%T395T%' ) ORDER BY IF(`products_sort`.`sort` IS NOT NULL,`products_sort`.`sort`,`products`.`sort`) ASC, `products`.`id` DESC LIMIT 0,8