我有三个表Team
和User_Has_Team
以及User
现在,我希望删除User_Has_Team
中Username
等于User_id
1的实体。
你会如何解决这个问题?
答案 0 :(得分:2)
DELETE FROM User_Has_Team WHERE users_id=1
如果你想删除给定用户名的记录,那就更难了
DELETE FROM User_Has_Team AS uht INNER JOIN users AS u ON u.id=uht.users_id WHERE u.name="Bob";
答案 1 :(得分:0)
“丑陋”的方式:
delete from user_has_team
where username in (select username from user where id=1);
“漂亮”的方式是user1032531
的答案