не корректный запрос по выводу доп. свойств
не корректный запрос по выводу доп. свойств
Добрый день
есть запрос
SELECT `shop_items_catalog_table`.`shop_groups_id`,
count(`shop_items_catalog_table`.`shop_items_catalog_item_id`) as count
FROM `shop_items_catalog_table` LEFT JOIN shop_list_of_properties_table
ON shop_items_catalog_table.shop_shops_id = shop_list_of_properties_table.shop_shops_id
LEFT JOIN shop_properties_items_table
ON shop_items_catalog_table.shop_items_catalog_item_id = shop_properties_items_table.shop_items_catalog_item_id
AND shop_properties_items_table.shop_list_of_properties_id = shop_list_of_properties_table.shop_list_of_properties_id
WHERE
(shop_list_of_properties_table.shop_list_of_properties_id=165 AND shop_properties_items_table.shop_properties_items_value = '2'
OR shop_list_of_properties_table.shop_list_of_properties_id=156 AND shop_properties_items_table.shop_properties_items_value = '1'
OR shop_list_of_properties_table.shop_list_of_properties_id=146 AND shop_properties_items_table.shop_properties_items_value = '1002'
)
GROUP BY shop_groups_id HAVING 1
Такой запрос выдает 4 товара, но только 2 товара соответствуют всем свойствам одновременно. То есть данный запрос выдает лишние товары. Как мне правильно отсортировать товары?