troubleshooting Question

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

Avatar of Cosmic_Cake
Cosmic_Cake asked on
MySQL Server
4 Comments1 Solution317 ViewsLast Modified:
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?
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros