Reputation: 8084
I have a table A
col-PK col2 col3 col4
1 a aa aaa
2 b bb bbb
I have created a new table B with three columns only
col-PKB colOne ColTwo
I want below as the Final Output
Table A
col-PK col2 col3 col4
1 a aa aaa
2 b bb bbb
Table B
col-PKB colOne ColTwo
1 a aa
2 b bb
Solution I looked into SO LINK. But I think I need to use select
statement as I have multiple columns
to copy. Please guide me here. I am lost.
Upvotes: 0
Views: 2034
Reputation: 2784
You can use INSERT INTO
with a SELECT
-query of the columns you want to add:
INSERT INTO tableB (col-PKB, colOne, ColTwo)
SELECT
col-PK,
col2,
col3
FROM tableA;
Upvotes: 1
Reputation: 9123
Try like this:
INSERT INTO table (column)
SELECT a_column
FROM a_table
In your case,
INSERT INTO tableB (
col-PKB, colOne, ColTwo
)
SELECT col-PK, col2, col3
FROM tableA
Upvotes: 1