如果您不知道 id,并且只知道与另一个表相关的信息,如何进行更新

发布于 2024-11-04 14:50:41 字数 482 浏览 0 评论 0原文

我正在尝试执行此查询:

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 技术交流群。

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

发布评论

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

评论(3

疾风者 2024-11-11 14:50:41

这是针对 MySQL 的:

UPDATE asignaturasemestre AS a
     , datosgenerales AS d
SET  a.asignatura11='cambiado' 
WHERE a.iddatosgenerales=d.iddatosgenerales 
  AND d.curp='CURP'

这是针对 SQL-Server 的:

UPDATE a
SET  a.asignatura11='cambiado' 
FROM asignaturasemestre AS a
    JOIN datosgenerales AS d
        ON a.iddatosgenerales=d.iddatosgenerales 
WHERE d.curp='CURP'

This is for MySQL:

UPDATE asignaturasemestre AS a
     , datosgenerales AS d
SET  a.asignatura11='cambiado' 
WHERE a.iddatosgenerales=d.iddatosgenerales 
  AND d.curp='CURP'

And this for SQL-Server:

UPDATE a
SET  a.asignatura11='cambiado' 
FROM asignaturasemestre AS a
    JOIN datosgenerales AS d
        ON a.iddatosgenerales=d.iddatosgenerales 
WHERE d.curp='CURP'
秉烛思 2024-11-11 14:50:41
update asignaturasemestre,datosgenerales 
set asignatura11='cambiado' 
where asignaturasemestre.iddatosgenerales=datosgenerales.iddatosgenerales 
and datosgenerales.curp='CURP'
update asignaturasemestre,datosgenerales 
set asignatura11='cambiado' 
where asignaturasemestre.iddatosgenerales=datosgenerales.iddatosgenerales 
and datosgenerales.curp='CURP'
友谊不毕业 2024-11-11 14:50:41

现在我找到了答案,

update asignaturasemestre set asignatura11='cambiado' 
where iddatosgenerales=(select datosgenerales.iddatosgenerales from datosgenerales inner join asignaturasemestre on
datosgenerales.iddatosgenerales=asignaturasemestre.iddatosgenerales where curp='123ABC');

我的查询正常,但是当我输入 iddatosgenerales 时,我做了一个查询,使用 curp 用户给了我获取 iddatosgenerales

Now i have found the answer it is

update asignaturasemestre set asignatura11='cambiado' 
where iddatosgenerales=(select datosgenerales.iddatosgenerales from datosgenerales inner join asignaturasemestre on
datosgenerales.iddatosgenerales=asignaturasemestre.iddatosgenerales where curp='123ABC');

I did the query normal, but when i put the iddatosgenerales i do a query getting the iddatosgenerales with curp user gave me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文