大家好我有一个项目,我需要使用mysql中的join同时删除4个表 这是我的疑问:
DELETE product_tbl, product_rebate, product_terms, product_cashp, product_downpayment
FROM product_tbl INNER JOIN product_rebate ON product_tbl.Prod_ID = product_rebate.Prod_ID
INNER JOIN product_terms ON product_tbl.Prod_ID = product_terms.Prod_ID
INNER JOIN product_cashp ON product_tbl.Prod_ID = product_tbl.Prod_ID;
它不起作用它给了我一个错误:#1109 - MULTI DELETE中的未知表'product_tbl'
答案 0 :(得分:0)
MySQL使用INNER JOIN DELETE JOIN
DELETE T1, T2
FROM T1
INNER JOIN T2 ON T1.key = T2.key
WHERE condition
试试这个: -
DELETE product_tbl, product_rebate, product_terms, product_cashp,
product_downpayment
FROM product_tbl
INNER JOIN product_rebate
ON product_tbl.Prod_ID = product_rebate.Prod_ID
INNER JOIN product_terms
ON product_tbl.Prod_ID = product_terms.Prod_ID
INNER JOIN product_cashp
ON product_tbl.Prod_ID = product_cashp.Prod_ID;
答案 1 :(得分:0)
试试这个,
DELETE product_tbl, product_rebate, product_terms, product_cashp,
product_downpayment
FROM product_tbl
INNER JOIN product_rebate
ON product_tbl.Prod_ID = product_rebate.Prod_ID
INNER JOIN product_terms
ON product_tbl.Prod_ID = product_terms.Prod_ID
INNER JOIN product_cashp
ON product_tbl.Prod_ID = product_cashp.Prod_ID;
我认为你在最后一次内部联接中犯了错误,
INNER JOIN product_cashp
ON product_tbl.Prod_ID = product_tbl.Prod_ID; -- both side same table?