Reputation: 190
I have one extra (id AI) column in B table, How can I fill all the data from A table and set id as null?
Table A
|---------------------|------------------|
| id | EmployeeName |
|---------------------|------------------|
| 1 | ABC1 |
|---------------------|------------------|
| 2 | ABC2 |
|---------------------|------------------|
| 3 | ABC3 |
|---------------------|------------------|
Table B
|----------------------|---------------------|------------------|
| id | empid | EmployeeName |
|----------------------|---------------------|------------------|
| | | |
|----------------------|---------------------|------------------|
| | | |
|----------------------|---------------------|------------------|
| | | |
|----------------------|---------------------|------------------|
Here we only have 2 columns but say we have many columns corresponding to a dynamic query.
here is the query I am trying
insert into B (select null, * from A);
Upvotes: 0
Views: 1866
Reputation: 7114
This way should do it:
INSERT INTO B (SELECT NULL, A.* FROM A);
You just need to append the table name A.
to the Asterix.
Upvotes: 1
Reputation: 384
You can try inserting only to the specified columns in B table. Then the column which is not present automatically gets populated as NULL
INSERT INTO table2 (empid,EmployeeName)
SELECT Id,EmployeeName
FROM table1
WHERE condition;
Upvotes: 3