mysql如何减少查询时间

时间:2018-09-27 10:29:01

标签: mysql

这是sql(mysql):

  

表产品和product_sale_app

它将传入两个参数,appkey是表product_sale_app的属性; category是表product的属性。我需要从表product中获取effect_date,product_id,name并使用上述条件。

SELECT effect_date,
       product_id,
       name
    FROM product
    WHERE product_id IN
        (SELECT product_id
         FROM product_sale_app
         WHERE appkey =88888
           AND product_id IN
             (SELECT product_id
              FROM product
              WHERE category =1 ) )

1 个答案:

答案 0 :(得分:0)

使用JOIN product_id代替子查询,然后将条件放在WHERE子句中。

请尝试以下操作:

SELECT p.effect_date,
       p.product_id,
       p.name
FROM product AS p 
JOIN product_sale_app AS psa ON psa.product_id = p.product_id 
WHERE p.category = 1 AND psa.appkey = 88888