Avatar of Cosmic_Cake
Cosmic_Cake
 asked on

How to insert 2 new columns based on value in existing column in DB

I want to insert 2 new columns to an already existing/populated table in my database.

I have 2 columns in an excel file, the columns are called 'weight' and 'color'. The condition is that the values in both these columns are associated with the value in a column called 'model_number' (this is unique, the value in this column is not replicated).
The column 'Model_Number' is also in the excel file.

My excel file is organised in such a way that it should be easy enough to execute this query.

Excel file sample:
Column Weight     Column Color    Column Model_Number (this column is already in DB)
3kg                        Red                     4545
5kg                        Green                 8789
2KG                       Blue                    7987
3KG                       Blue                    4332

So for example where the value in Column 'Model_Number' is 4545 the value 3kg will be added to Column Weight and the value Red will be add to Column Color in the DataBase.

What SQL code do I need to use here?
Do I have to add the 2 new columns first before adding the values?
Also I am concerned that by inserting these 2 new columns and adding values that I will reset the 'timestamp' value column in each row which I don't want to do. Is there a way to keep the original timestamp value?
MySQL Server

Avatar of undefined
Last Comment
Cosmic_Cake

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
johanntagle

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Cosmic_Cake

ASKER
Thanks for your reply, it makes sense and it's a great answer and I will accept it as a solution. I'm just having a bit of trouble with finding a simple example with LOAD DATA INFILE.
johanntagle

If you're having problems with LOAD DATA INFILE post a new related question showing what you have tried, including a file containing the sample csv data.  Thanks.
Cosmic_Cake

ASKER
ok
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy