我不知道这是否可能有相同的结果下面的请求不使用子查询选择:与WHERE NOT IN条件无子查询
SELECT p1.id
FROM products p1
WHERE NOT p1.id IN (
SELECT p2.id
FROM products p2
JOIN product_translations t
ON t.product_id = p2.id
AND t.locale = 'fr'
);
正如你所看到的,products
行可以有很多product_translations
行(0..n)。
预期结果必须是只有没有product_translations
且区域设置为fr
的产品。
你想这样做,没有一个子查询(尽管NOT EXISTS可能比NOT IN更快)为什么 – 2014-09-24 09:15:50
SELECT p2.id FROM产品P2 LEFT JOIN product_translations吨 ON t.heroshop_record_id = p2.id AND t.locale = 'FR' WHERE t.heroshop_record_id为null – mhn 2014-09-24 09:16:54
@a_horse_with_no_name完全相同,也可以是左连接到product_translations并通过使用IS 'product_translations'表上一列的NULL条件。 – 2014-09-24 09:17:55