有兩個表:report(它有一個主鍵reportId和一個位域稱爲遷移)和report_detail(它有一個外鍵reportId)。我想刪除所有來自report_detail有哪些,報告表,已經遷移= 1。這是選擇所有我想要的行選擇查詢reportId行:我有一個SQL刪除查詢
select *
from report r inner join report_detail d
on r.reportId = d.reportId
where migrated = 1
這是否會刪除查詢做我想要什麼或者我做錯了什麼?
delete from report_detail
where exists(
select *
from report r inner join report_detail d
on r.reportId = d.reportId
where migrated = 1
)
請與該品牌的數據庫(S)使用,例如標記您的問題'mysql'或'sql-server'。答案可能會有所不同,具體取決於您使用的數據庫。 – 2010-08-23 16:58:33