如果您不知道 id,并且只知道与另一个表相关的信息,如何进行更新
我正在尝试执行此查询:
UPDATE asignaturasemestre
SET asignatura11 = 'cambiado'
WHERE asignaturasemestre.iddatosgenerales = datosgenerales.iddatosgenerales
AND datosgenerales.curp = 'CURP'
我知道这很糟糕,但这就是想法:
如您所见,我不知道 iddatosgenerales
,但我确实知道它有一个外键( iddatosgenerales
)。用户只会写入 curp,因此 curp 不在另一个表中,所以我需要更新另一个表,但我不知道该行的 id。 正如我告诉过你的,我只知道 CURP 列,但它位于另一个表中(这是唯一的)。但它不是主键 - 它不介意,id 是 iddatosgenerales ,它是我想要更新的另一个表中的外键。
I am trying to do this query:
UPDATE asignaturasemestre
SET asignatura11 = 'cambiado'
WHERE asignaturasemestre.iddatosgenerales = datosgenerales.iddatosgenerales
AND datosgenerales.curp = 'CURP'
I know this is bad, but this is the idea:
As you can see, I don't know the iddatosgenerales
, but I do know it has a foreign key (iddatosgenerales
). The users will write the curp only, so with that curp is not in the another table, so I need to update the another table but I don't know the id of this row.
As I have told you, I just know the CURP
column, but this is in the another table (this is unique). But it is not the primary key - it doesn't mind, the id is iddatosgenerales
which is a foreign key in the another table where I want to update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是针对 MySQL 的:
这是针对 SQL-Server 的:
This is for MySQL:
And this for SQL-Server:
现在我找到了答案,
我的查询正常,但是当我输入 iddatosgenerales 时,我做了一个查询,使用 curp 用户给了我获取 iddatosgenerales
Now i have found the answer it is
I did the query normal, but when i put the iddatosgenerales i do a query getting the iddatosgenerales with curp user gave me