SQL Insert语句,其中单值从另一个表中选择

时间:2014-01-14 00:55:12

标签: sql

我有以下SQL:

INSERT INTO Invite VALUES (NULL,?,(SELECT id FROM User WHERE name = ?),?);

然而,这似乎不起作用。

谁能告诉我我做错了什么?

更新

以下php代码给了我erro代码1136:

    $sql = 'INSERT INTO Invite SELECT NULL, ?, id, ? FROM User WHERE username = ?';
$variables = array($team_id,$_SESSION['User']['id'],$username);
$result = $this->db->prepTemplate($sql, 'iis', $variables);

1 个答案:

答案 0 :(得分:3)

INSERT INTO Invite 
SELECT NULL, ?, id, ?
FROM User
WHERE name = ?