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

188
Visualizações
How to insert values in a table taking value from same table?

If i have table named shipments with columns origin_state and destination_state. I want a new column named st_st with the value origin_state _ destination_state. For example, if a row has SC as origin and GA as a destination. I should get SC_GA in the st_st

I tried

INSERT INTO shipments(ST_ST) 
SELECT CONCAT(`Origin_state` , '_' ,`Destination State`) AS ST_ST 
From shipments;

this query starts to insert the values at the end of the table not to the corresponding row. Please help.

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

0

Use a generated column:

alter table shipments add column st_st varchar(255) generated always as
    concat(`Origin_state` , '_' ,`Destination State`) ;

You can also change the values using update:

update shipments
    set st_st = concat(`Origin_state` , '_' ,`Destination State`);

However, a generated column ensures that the value in st_st is always consistent, even for new rows and if the values change in existing rows.

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