MySQL:DELETE FROM 包含子查询中的信息

发布于 2024-12-09 23:21:22 字数 329 浏览 7 评论 0原文

我有一个表delete_requests,其中存储用户表条目的删除请求的ID。是否可以以delete_requests中的信息为条件从用户中删除?

我的问题是,结果集通常不限于一行,而是返回几行。

DELETE FROM users WHERE id=(SELECT id FROM delete_requests)

所以 MySQL 抱怨:

#1242 - Subquery returns more than 1 row

可以在一条语句中完成此操作,而不将逻辑放入正在执行的应用程序中吗?

I have a table delete_requests where I store the id's for delete requests for the entries of my users table. Is it possible to delete from users with the information from delete_requests as a condition?

My problem is, that the result set will usually not be limited to one row but return several.

DELETE FROM users WHERE id=(SELECT id FROM delete_requests)

So MySQL complains:

#1242 - Subquery returns more than 1 row

Can this be done in one statement without putting the logic into the executing application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

箜明 2024-12-16 23:21:22

使用 IN 子句

DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)

Use the IN clause

DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
可可 2024-12-16 23:21:22

您可以使用 in 子句。

DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)

You can use the in clause.

DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
情丝乱 2024-12-16 23:21:22
DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文