[SQL]多对多查询、删除、修改
程序员文章站
2022-07-12 16:13:30
...
SELECT u.USERNAME,p.privilege FROM DCB_CS_USER u,DCB_CS_PRIVILEGE p,DCB_CS_USER_PRIVILEGE_MAPPING m where u.username = m.username and p.privilege_id = m.privilege_id; select u.username, p.privilege from DCB_CS_USER u inner join DCB_CS_USER_PRIVILEGE_MAPPING m on m.username = u.username inner join DCB_CS_PRIVILEGE p on p.privilege_id = m.privilege_id;
user表,权限表和中间表
参考:https://blog.csdn.net/xianzgiyou/article/details/50210431
删除可以使用join:
delete from (select m.username, p.privilege from DCB_CS_USER_PRIVILEGE_MAPPING m inner join DCB_CS_PRIVILEGE p on m.privilege_id = p.privilege_id) t where t.username = 'test3' and t.privilege = 'read';
但是编辑不可以使用join的多表修改