mysql запрос типа SELEC
Есть запрос:
SELECT `products`.*, `attributes`.`id`
AS `attributes.id`, `attributes`.`name_en`
AS `attributes.name_en`, `attributes`.`name_fr` AS `attributes.name_fr`, `attributes`.`name_es`
AS `attributes.name_es`, `attributes`.`slug` AS `attributes.slug`, `attributes`.`order_by`
AS `attributes.order_by`, `attributes->product_attribute`.`id`
AS `attributes.product_attribute.id`, `attributes->product_attribute`.`used_variation`
AS `attributes.product_attribute.used_variation`, `attributes->product_attribute`.`attributeId`
AS `attributes.product_attribute.attributeId`, `attributes->product_attribute`.`productsId`
AS `attributes.product_attribute.productsId`
FROM (SELECT `products`.`id_product` FROM `products` AS `products` WHERE ( SELECT `product_category`.`id` FROM `product_categories` AS `product_category` INNER JOIN `Categories` AS `Category` ON `product_category`.`categoryId` = `Category`.`id_category` AND `Category`.`slug` = 'wedding-dress' WHERE (`products`.`id_product` = `product_category`.`productsId`) LIMIT 1 ) IS NOT NULL AND ( SELECT `product_attribute`.`id` FROM `product_attributes` AS `product_attribute` INNER JOIN `attributes` AS `attribute` ON `product_attribute`.`attributeId` = `attribute`.`id` AND `attribute`.`slug` IN ('color', 'dress-lenght') WHERE (`products`.`id_product` = `product_attribute`.`productsId`) LIMIT 1 ) IS NOT NULL GROUP BY `id_product`
having count(*) = 1
ORDER BY rand() LIMIT 0, 24) AS `products` INNER JOIN ( `product_categories` AS `Categories->product_category` INNER JOIN `Categories` AS `Categories` ON `Categories`.`id_category` = `Categories->product_category`.`categoryId`) ON `products`.`id_product` = `Categories->product_category`.`productsId` AND `Categories`.`slug` = 'wedding-dress' INNER JOIN ( `product_attributes` AS `attributes->product_attribute` INNER JOIN `attributes` AS `attributes` ON `attributes`.`id` = `attributes->product_attribute`.`attributeId`) ON `products`.`id_product` = `attributes->product_attribute`.`productsId` AND `attributes`.`slug` IN ('color', 'dress-lenght') ORDER BY rand()
Суть в том что мне нужно вывбрать те продукты в которых есть атрибут и color и dress-lenght
Мне нужно чтобы оно выбрало только продукты в которорых атрибутов 2
типо having count(`attributes.product_attribute.productsId`) = 2но мне выдает ошибку
Error Code: 1054. Unknown column 'attributes.product_attribute.productsId' in 'having clause' как достучаться до product_attribute или есть другое решения?
