Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

325
Visualizações
How do I change the value of one field in SQL record to a value from another table?

First of all, I'm sorry if this is a bit of a dumb question. I checked what's written in similarly phrased questions like "How do I update fields from one table with values from another table" but the content doesn't seem to match what I'm trying to do.

Let's say I have a table called site_users:

user_id login password user_id2
2 user password 1
7 access xyz 2
11 otherlogin abc 3
15 somebody defg 4
22 user qwert 5

Then I have a lot of other tables in the same database, that have some columns of various names that are actually corespondent to the "user_id" of the "site_users" table. There are no relations set or anything like that. I want to change the values in the fields of those other tables to user_id2. So let's say I have a table: user_options:

admin_id perms1 perms2
2 1 12139389
7 1 13232111

I want to change it to:

admin_id perms1 perms2
1 1 12139389
2 1 13232111

How can I do that? This is the first time I'm doing anything other than just simple mass changes of text with some regex :/

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If i am understanding your question correctly you should be able to do following where table1 is top table and table2 is table you are trying to update:

update table2 t set admin_id = (select user_id2 from table1 where user_id = t.admin_id)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda