【发布时间】:2011-05-25 05:54:52
【问题描述】:
我有两个表命名为:
- table_product
- table_user_ownned_auction
table_product
specific_product_id astatus ...
(primary_key,autoinc)
--------------------------------------
1 APAST ...
2 ALIVE ...
3 ALIVE ...
4 APAST ...
5 APAST ...
table_user_ownned_auction
own_id specific_product_id details
----------------------------------------
1 1 XXXX
2 5 XXXX
我需要选择atatus = APAST,而不是在表 2 中。
这意味着,在上述结构表 1 中有 3 个 APAST 状态(1、4、5)。但在表 2 中,specific_product_id (1,5) 仅存储,所以我需要选择 specific_product_id = 4
我使用了这个查询
SELECT *
FROM table_product
WHERE astatus = 'APAST'
AND specific_product_id NOT IN (SELECT specific_product_id
FROM table_user_ownned_auction )
...需要这么长时间:
查询耗时 115.1039 秒
...执行。
解释计划
我怎样才能优化它或任何其他方式来选择我想要的?
【问题讨论】:
标签: mysql sql query-optimization