需要使用联接更改此查询

时间:2017-08-31 22:45:51

标签: mysql database mysqli

我需要更改我的Mysql旧查询以使用连接而不是使用旧格式,目前我的查询中的问题是它获得了超过1000个重复结果实际应该返回的行数是4我尝试了很多东西但没有运气。这是我的查询

SELECT pc.* 
FROM product_cache pc 
WHERE pc.category = 'Connectors' 
    AND (EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'series' AND value = 'SMA')) 
    AND (EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'orientation' AND value = 'Straight')) 
    AND (EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'connection' AND value = 'Male') 
        OR EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'connection' AND value = 'Plug')) 
    AND (EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'mount' AND value = '2 Hole Flange')) 
    AND (EXISTS (SELECT * 
                FROM product_attr_cache 
                WHERE product_cache_id = pc.id AND name = 'termination' AND value = 'Receptacle-Solder'))

1 个答案:

答案 0 :(得分:0)

您可以添加Distinct以避免重复数据。

tools_webrtc/android/build_aar.py