2012-06-06 76 views

回答

2

我假設你有2和表之間的關係id

select * from OrderTable 
where orderdetails_id not in (select id from OrderDetailTable) 

,並進行刪除

delete from OrderTable 
where orderdetails_id not in (select id from OrderDetailTable) 
0
SELECT o.* 
FROM OrderTable o 
LEFT JOIN OrderDetailTable od ON od.idOrderTable = o.id 
WHERE od.id IS NULL; 

od.id可以從任何OrderDetailTable字段不能爲null。

0

假設OrderTable有一欄的ID,並OrderDetailTable有一列orderTable_id

select * from OrderTable 
WHERE id not in (
select ot.id from OrderTable ot inner join OrderDetailTable odt on odt.orderTable_id = ot.id 
) 
相關問題