2010-11-26 67 views
1

Qe的:1)MySQL查詢抽空

select 
    a.finishproductid 
from 
    tblt_invoiceorderitems a, tblm_invoiceorder b 
where 
    b.invoiceorderdate <= 'Current Date' and 
    a.invoiceorderid = b.invoiceorderid 

---它已超過16K的記錄。

Qe的:2)

select jobcardid, stockcode 
from tblm_finishproduct 
where productionentrydate <= 'Current Date' 

---居然也超過16K記錄。

現在我想從第二個查詢不在第一個查詢。現在

select jobcardid, stockcode 
from 
    tblm_finishproduct 
where 
    productionentrydate <= 'CurrrntDate' and 
    finishproductid not in 
    (
    select 
     a.finishproductid 
    from 
     tblt_invoiceorderitems a, tblm_invoiceorder b 
    where 
     b.invoiceorderdate <= 'CurrrntDate' and 
     a.invoiceorderid = b.invoiceorderid 
); 

其服用時間

+0

請爲SQL使用代碼塊。 – robert 2010-11-26 12:33:46

回答

0

這不解決您的問題,但你不應該在你那裏clause--使用a.invoiceorderid = b.invoiceorderid試試這個查詢來代替第一個。 Natural join比創建整個表的交叉乘積和僅選擇匹配的行更有效。

select a.finishproductid 
from tblt_invoiceorderitems a 
natural join tblm_invoiceorder b 
where b.invoiceorderdate <= 'Current Date' 
0

從刪除此不:

b.invoiceorderdate <= 'CurrrntDate' and 
0

「select table1,table2,table3」maby的結果是16k^3或16k^2。您需要使用主鍵進行「內部連接」或「連接」來關閉搜索。

看到你。