Reputation: 28763
Iam inserting multiple records from one table to another table like
INSERT INTO table3 (
iSysRecDeleted,
iUserId
)
SELECT
table2.iDeleteId,
(SELECT iUserIdOld FROM table1 WHERE table1.col1=table2.col2)
FROM table2
But it is giving me "Sub query returns more than 1 row".iUserIdOld
had multiple entries with repetive in table1
.Also I have to insert column3 from another table which will be not relevant to table1 and table2 so I don't have to use Join.Could anyone please tell me to do it in a right way.
Thanks in advance.
Upvotes: 0
Views: 51
Reputation: 69440
Try this:
INSERT INTO table3 (
iSysRecDeleted,
iUserId
)
SELECT table2.iDeleteId, table1.iUserIdOld
from table2 join table1 on table1.col1=table2.col2
Upvotes: 1