如果你不知道id,你怎么做更新,只是你知道另一个表关系的信息

时间:2021-07-23 23:07:47

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.

正如你所看到的,我不知道iddatosgenerales,但我知道它有一个外键(iddatosgenerales)。用户只会编写curp,所以这个curp不在另一个表中,所以我需要更新另一个表,但我不知道这行的id。正如我告诉你的那样,我只知道CURP列,但这是在另一个表中(这是唯一的)。但它不是主键 - 它不介意,id是iddatosgenerales,这是我要更新的另一个表中的外键。

3 个解决方案

#1


5  

This is for MySQL:

这适用于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:

这适用于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'

#2


0  

update asignaturasemestre,datosgenerales 
set asignatura11='cambiado' 
where asignaturasemestre.iddatosgenerales=datosgenerales.iddatosgenerales 
and datosgenerales.curp='CURP'

#3


0  

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

我做了正常的查询,但是当我把iddatosgenerales我做一个查询得到iddatosgenerales与curp用户给了我

#1


5  

This is for MySQL:

这适用于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:

这适用于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'

#2


0  

update asignaturasemestre,datosgenerales 
set asignatura11='cambiado' 
where asignaturasemestre.iddatosgenerales=datosgenerales.iddatosgenerales 
and datosgenerales.curp='CURP'

#3


0  

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

我做了正常的查询,但是当我把iddatosgenerales我做一个查询得到iddatosgenerales与curp用户给了我