我不知道這是否可能有相同的結果下面的請求不使用子查詢選擇:與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