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.
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;
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.