PG联表删除语法
DELETE
FROM
sys_user USING sys_user su
JOIN sys_user_role sur ON su.id = sur.user_id
WHERE
sur.role_id = 500; --错误写法,错误写法,错误写法!!!如果role_id存在会导致删除sys_user全表
DELETE
FROM
sys_user su USING sys_user_role sur
WHERE
su.id = sur.user_id
AND sur.role_id = 500; --正确写法
DELETE
FROM
sys_user su
WHERE
EXISTS ( SELECT 1 FROM sys_user_role sur WHERE su.id = sur.user_id AND sur.role_id = 500 ); --A表为小表,B表为大表时,性能更高的写法