Skip to content
Advertisement

Update table using select and where

I have two tables:

I need do create a column int cidadaos_id on table ficha_atendimento_cidadao and I like to fill it with the id from cidadaos table, like it:

But it’s not works… Any help?

Advertisement

Answer

You need to do two separate operations to achieve that. Firstly, add the cidadao_id column to your table. Then, UPDATE its values from the cidados table:

You may also want to add a FOREIGN KEY on the cidadao_id value:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement