mysql插入带有select查询以插入多行

时间:2017-12-08 11:07:59

标签: mysql

如何使用insert和select query插入多行。

Exception calling "SendWait" with "1" argument(s): "Access is denied"
    + CategoryInfo          : NotSpecified: (Exception calli...cess is denied":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

1 个答案:

答案 0 :(得分:2)

您可以使用union all

INSERT INTO contacts(`studentId`, `contactId`, `firstName`, `lastName`) 
    SELECT studentId, '1234', 'kavin', 'kumar'
    FROM student
    WHERE sampId = '8580'
    UNION ALL
    SELECT studentId, '108', 'karthi', 'kumar'
    FROM student 
    WHERE sampId = '5650';

如果id列是数字,则不要在值周围使用单引号。