使用其他表值删除SQL

时间:2014-01-13 23:34:28

标签: sql

我有三个表TeamUser_Has_Team以及User

现在,我希望删除User_Has_TeamUsername等于User_id 1的实体。

你会如何解决这个问题?

2 个答案:

答案 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

的答案