【发布时间】:2013-12-26 09:21:24
【问题描述】:
这是我的代码:
SELECT *
FROM (`View_Products_With_Category`)
WHERE `category_id` = '47'
AND `top_id` = 0
AND (select count(product_id) from Modules where product_id=`View_Products_With_Category`.id)= 0
ORDER BY `order`, `sub_order`, `code`
此查询从 15.000 条记录中返回 8 行。我的问题是 (select count(product_id) from Modules where product_id=View_Products_With_Category.id)= 0 行工作太慢了。
如果第一个条件为 TRUE,我需要一个语法来让慢行工作。
这可能吗?
【问题讨论】:
-
是的,有可能,但在您的特定情况下,最好将子查询转换为
JOIN
标签: mysql sql select join left-join