SELECT `p`.`url_product`, `p`.`rus_product`, `p`.`home`, `p`.`phone`,
`p`.`cx`, `p`.`cy`, `s`.`rus_street`, `s`.`url_street`,
`c`.`categories`, `r`.`rating`
FROM `products` AS `p`
LEFT JOIN `streets` ON `s`.`id` = `p`.`id_street`
LEFT JOIN (
SELECT `p`.`id` AS `product_id`, GROUP_CONCAT(CONCAT('<a href=\"/$url_punkt/', `c`.`url_category`, '/\">', `rus_category`, '</a>')) AS `categories`
FROM `products` AS `p`
JOIN `categories` AS `c` ON `c`.`product_id` = `p`.`id`
WHERE `p`.`id_punkt` = :id_punkt
AND `p`.`id` IN (
SELECT `product_id`
FROM `category_product`
WHERE `category_id` = :id_category
)
GROUP BY `p`.`id`
) AS `c` ON `c`.`product_id` = `p`.`id`
LEFT JOIN (
SELECT `p`.`url_product` AS `url_product`, AVG(`pr`.`rating`) AS `rating`
FROM `products` AS `p`
JOIN `products_reviews` AS `pr`
ON `pr`.`type` = `p`.`url_product`
WHERE `p`.`id_punkt` = :id_punkt
AND `p`.`id` IN (
SELECT `product_id`
FROM `category_product`
WHERE `category_id` = :id_category
)
GROUP BY `p`.`url_product`
) AS `r` ON `r`.`url_product` = `p`.`url_product`
WHERE `p`.`id_punkt` = :id_punkt
AND `p`.`id` IN (
SELECT `product_id`
FROM `category_product`
WHERE `category_id` = :id_category
)