错误:通过变量从其他表插入值

时间:2012-06-28 06:14:33

标签: mysql sql mysql-error-1064

这是我的疑问:

set @agent_id = select agnt.id from agent agnt , session ses 
where ses.session_id = '0021a7ca-6e' and ses.employee_id = agnt.employee_id ;

insert into inquiry_placed_by(inquiry_id , agent_id) values(1 , @agent_id); 

我得到了这个错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 'select agnt.id from agent agnt , 
session ses where ses.session_id = '0021a7ca-6e' at line 1

这种操作在mysql中是可行的还是我错过了什么 感谢。

1 个答案:

答案 0 :(得分:1)

替换前两行:

set @agent_id = (
select agnt.id from agent agnt , session ses 
where ses.session_id = '0021a7ca-6e' and ses.employee_id = agnt.employee_id ) ;