请帮我解决这个MySQL查询。我已经玩了很长时间了。也许它需要一双新鲜的眼睛。
两个表格:锁定和会话
locks
--------------
id session_id
--------------
1 sajf4$Jf9422jd
2 2jf*4j2okg9092
3 J8j4j4ffss93o2
------------------
sessions
-------------------------
id user_id
-------------------------
sajf4$Jf9422jd 14
J8j4j4ffss93o2 14
2jf*4j2okg9092 21
-------------------------
我想删除其中user_id为session = 14
的锁中的所有行答案 0 :(得分:4)
DELETE FROM locks
WHERE session_id IN (SELECT id FROM sessions WHERE user_id = 14)
答案 1 :(得分:2)
DELETE FROM locks
WHERE session_id
=(SELECT id
FROM sessions
WHERE user_id
= 14);
答案 2 :(得分:2)
从其中session_id的锁中删除(select_id来自其中user_id = 14的会话)
答案 3 :(得分:1)
没有子查询的另一种方法:
从锁中删除 使用锁 在sessions.id = locks.session_id上加入会话 其中sessions.user_id = 14
答案 4 :(得分:0)
DELETE locks, sessions FROM locks INNER JOIN sessions WHERE locks.session_id=sessions.id;