【发布时间】:2011-12-11 10:58:25
【问题描述】:
我正在尝试从同一表的另一列中确实存在的一列中识别值
子查询
SELECT DISTINCT `Wear it With - Outfits 1`
FROM `product list`
WHERE `Wear it With - Outfits 1` NOT IN (SELECT `sku`
FROM `product list`)
...在 2.7287 秒内返回结果
我尝试用左连接替换子查询
SELECT DISTINCT table1.`Wear it With - Outfits 1`
FROM `product list` as table1
LEFT JOIN `product list` as table2 ON table1.`Wear it With - Outfits 1`=table2.sku
WHERE table2.sku IS NULL
AND table1.`Wear it With - Outfits 1` IS NOT NULL
...在 5.7651 秒内返回结果
通常连接返回结果要快得多。所以我相信我在查询中做了一些有趣的事情? 但是找不到任何原因为什么我的子查询运行得比
【问题讨论】:
-
是的,MySQL 并通过 phpmyadmin 运行这些查询
-
你真的应该简化你的例子,而不是'穿它 - 服装 1' 只是替换为'foo'或类似的东西。这让你最初很难看到你真正想要做什么