So I have two tables. Table1 have two columns, col1 and col2, where col1 is already filled. The other table, Table2, has many columns but there is 1 column, sub, that I need and I need it to fill the 2nd column in Table1.
The problem when I use
INSERT INTO Table1 (col2) SELECT Table2.sub FROM Table2
is that, yes, it copies the content of the required column to Table1 but it creates a new row for each.
Table1 looks like:
+-----+------+
|col1 | col2 |
+-----+------+
|data | NULL |
+-----+------+
|data2| Null |
+-----+------+
After doing the INSERT query above, I get:
+-----+------+
|col1 | col2 |
+-----+------+
|data | NULL |
+-----+------+
|data2| Null |
+-----+------+
|Null | data4|
+-----+------+
|Null | data5|
+-----+------+
What I need to look like is:
+-----+-------+
|col1 | col2 |
+-----+-------+
|data | data4 |
+-----+-------+
|data2| data5 |
+-----+-------+
Any ideas?
try below query
OR
I believe you have col1 in Table2 too as without that you can’t compare two tables…
Let me know if it works….