Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!