marian marian - 2 years ago 104
SQL Question

How to copy 1 column from one db to another db and set constants for another column in the 1st db during the INSRT INTO statement?

I have database1 with table table1 and 3 columns: column1a, column1b, column1c
I have database2 with table table2 and 1 columns: column2a

I would like to copy the values from the database2 (from column2a) to database1 column1a and the others values of column1b and column1c set to a certain constant value e.g.

INSERT INTO database1.table1 (column1a,'column1b' = 'apple','column1c'= 'orange') SELECT `column2a` FROM database2.table2;

However, in the fisrt part if the statemnt are 3 values and in the second is only 1, so I suppose there is a problem and this statement is bad :(.

Any advice how to rewrite my mysql statement?

Answer Source

Here's the solution:

INSERT INTO database1.table1 (column1a, column1b, column1c)
SELECT column2a, 'apple', 'orange' FROM database2.table2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download