Search code examples
mysqlsqlmysql-error-1064

Error : Inserting values from other table via variable


This is my query :

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); 

This error i get :

#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

Is this kind of operation is possible in mysql or am i missing something.
Thanks.


Solution

  • Replace the first two lines:

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