我试图根据任何特定属性找出具有重复值的产品。假设我有一个属性MPN,并且必须获得共享相同MPN的所有产品。我设计了一个部分可行的查询,但我发现它调用了很少的属性值唯一的产品。
select e.entity_id as ID,n.value as name,e.sku as sku,m.value as mpn from `catalog_product_entity` as e
left join `catalog_product_entity_varchar` as m
on e.entity_id = m.entity_id and m.attribute_id=156
left join `catalog_product_entity_varchar` as n
on e.entity_id = n.entity_id and n.attribute_id=71
group by m.value having count(*)> 1 order by e.entity_id asc
似乎我的逻辑不够公平,无法得到我想要的东西。
任何数据库大师帮我解决?
答案 0 :(得分:0)
我已通过应用其他查询过滤掉结果来解决此问题。这可能不是一个好的解决方案,但它帮助了我。
从上面的查询得到结果后,我使用foreach循环来查找属性值是否唯一。
foreach($QueryCollection as $data){
$query1 = "select * from catalog_product_entity_varchar as cpev where cpev.attribute_id=156 and cpev.value='".$data['mpn']."'";
$IsDuplicate = $_conn2->fetchAll($query1);
if(count($IsDuplicate)>1){
//found this as duplicate
}
}
我在200左右的产品非常少,所以对我来说没关系,但我想这对于更高的数量来说并不好。