Link to home
Start Free TrialLog in
Avatar of 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?
Avatar of johanntagle
Flag of Philippines image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cosmic_Cake


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.
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.