本文介绍了sql从查询中删除结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张表,结构相同
clients
包含第 1+2 行clients3
仅第 2 行
clients
contains row 1+2clients3
only row 2
我想删除clients
表中的第2行
SELECT *
FROM clients
WHERE EXISTS (SELECT * FROM clients3 WHERE clients3.id = clients.id))
给了我第 2 行.但我不知道如何删除.
gives me the row 2. But I do not know how to delete.
DELETE *
FROM clients
WHERE (SELECT *
FROM clients
WHERE EXISTS (SELECT * FROM clients3 WHERE clients3.id = clients.id))
不起作用.
推荐答案
无需在查询中两次引用 clients
表并从 DELETE*
/code> 子句 -
No need to refer clients
table twice in your query and remove *
from DELETE
clause -
DELETE c1
FROM clients c1
INNER JOIN clients3 c3 ON c3.id = c1.id --INNER JOIN will work as EXISTS for 1-1 Relation
这篇关于sql从查询中删除结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!