Copy column data from one table to another

Asked

Viewed 111 times

4

I have 2 tables

"Orcamento" -> colunas ['id', 'cliente_id']
Essa tabela existe valores em 'cliente_id'

"Ordem_servicos" -> colunas ['id', 'cliente_id', 'orcamento_id']
essa tabela não existe valores em 'cliente_id'
a coluna 'orcamento_id' refere-se a coluna 'id' da tabela "Orcamento"

I need to copy the data from the cliente_id column of the table "Orcamento" to the table "ordem_servicos". but using 'orcamento_id' to specify

you have to copy the cliente_id of the column that orcamento_id equals the id of the table "orcamentos"

kind of like I’m trying to do but it’s not working.

    UPDATE ordem_servicos SET cliente_id = orcamentos.cliente_id
    FROM orcamentos 
    WHERE orcamentos.id = ordem_servicos.orcamento_id
  • can specify better what you need?

  • kkk.. yes bro I’ll redo then..

  • blz. edit and tell me

  • Ready bro see if now it’s gotten easier to understand

  • posted an example

1 answer

5


You need an update with Join. Something like this (untested, make a backup of the database before running):

UPDATE Ordem_servicos os
INNER JOIN orcamentos AS o
ON o.id = os.orcamento_id
SET os.cliente_id = o.cliente_id;
  • gave bro error..

  • #1064 - You have a syntax error in your SQL next to 'FROM Ordem_servicos AS INNER JOIN quotes AS o ON o.id = os.orcamento_id' on line 3

  • I updated, try again. I never remember in my head.

  • made the water turn wine mano.. only gave ambiguous because it lacked after SET put the.cliente_id

  • This :) Glad it worked out

  • kkkk.. monster! vlw brother success!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.