改寫sql命令我有三個表:使用IN
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
我試圖找到賣筆記本電腦製造商,但不是PC的。我想我已經用下面的命令實現了這個:
select product.maker
from product
where product.maker not in
(select maker
from pc, product
where product.model = pc.model)
and product.maker in
(select maker
from laptop, product
where product.model = laptop.model);
但是我想重寫這個而不使用IN和NOT IN。
提示:使用EXISTS'(...)'和'NOT EXISTS(...)' – wildplasser 2014-09-21 22:46:50
@wildplasser我的意思是不使用存在,我應該這樣說。我正在尋找一種只使用「基本」操作符來重寫的方法。 – 2014-09-21 22:49:51
恕我直言'存在(...)'**非常**基本。它比下面醜陋的'LEFT JOIN ... WHERE NULL'語法更古老。 – wildplasser 2014-09-21 23:02:40