从postgres数据库sql脚本中的多个表中删除记录

时间:2017-07-10 06:51:28

标签: sql postgresql sql-delete

我有一个场景如下。

我有五个表:merchantsuser_detailsuser_roletransient_paymentspayments

要求:如果transient_payments和payment表中不存在merchant_id,则该商家应从merchantsuser_detailsuser_role

中删除

我的查询:

DELETE FROM m,ud,ur USING merchants 
       INNER JOIN user_details 
       INNER JOIN user_role 
       where merchant_id not 
       exists (select * 
               from transient_payments 
               full join payments 
               on transient_payments.merchant_id = payments.merchant_id );
Error :ERROR:  syntax error at or near "," LINE 1: DELETE FROM m,ud,ur
USING merchants INNER JOIN user_details ...
                    ^

********** Error **********
ERROR: syntax error at or near "," SQL state: 42601 Character: 14

0 个答案:

没有答案