【问题标题】:Updating a row in a table while selecting another row from another table to show where to update更新表中的一行,同时从另一个表中选择另一行以显示更新位置
【发布时间】:2021-02-24 12:06:08
【问题描述】:

我有桌子:

__ Members __
ID(int) auto_increment
Email varchar(255) not null

__Options__
ID(int) auto_increment
FORMATION(int) not null

我需要构建一个 SQL 请求,在其中我可以使用 Email 更新我的行 Options.ID = Members.ID 的行 Options.Formation = 1 以识别选择了哪个用户。

有人知道吗? 我在互联网上搜索,但没有什么想要工作... :(

【问题讨论】:

  • (1) 标记您正在使用的数据库。 (2) 样本数据和预期结果会有所帮助。 (3)optionsmembers之间没有联系。

标签: php sql select sql-update where-clause


【解决方案1】:

假设你在options 表中有一个member_id,那么我认为你想要:

update options
    set formation = 1
    where member_id in (select m.id from members m where m.email = ?);

如果多个成员可以拥有相同的电子邮件,则使用in 而不是=

【讨论】:

  • 解决了!太感谢了 !我会尽快将您的回复标记为答案! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-03
  • 2023-03-22
  • 2021-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多