【发布时间】:2012-08-10 18:16:42
【问题描述】:
我在这里有这个选择:
select parent_id from sales_flat_order_status_history where status like '%whatever%' group by parent_id having count(parent_id) > 1
这个查询只运行几秒钟。现在我想在另一个选择中使用它,像这样:
select increment_id from sales_flat_order where entity_id in(
select parent_id from sales_flat_order_status_history where status like '%whatever%' group by parent_id having count(parent_id) > 1)
这会永远运行,所以我尝试一一插入 id:
select increment_id from sales_flat_order where entity_id in(329,523,756,761,763,984,1126,1400,1472,2593,3175,3594,3937,...)
这运行得很快,区别在哪里,我怎样才能让我的第一种方法运行得更快?
谢谢!
【问题讨论】:
标签: mysql query-optimization subquery