Jump to content

select and insert


Destramic

Recommended Posts

im unable to find an example when it comes to select and insert in my particular case, so any help would be greatly appreciated.

here is my 2 select queries which retrieve the department_id and task_type_id.  what i want to do it is use those two values inside an insert as well as adding additional values.

 

SELECT department_id FROM departments WHERE department = "Gas Servicing"
SELECT task_type_id FROM task_Types WHERE task_type = "Gas Service"

INSERT INTO property_appointments (property_id, department_id, task_type_id, notes, priority_days) 
                           VALUES (:property_id, ?, ?, :notes, 1)

 

is this possible please?

 

thank you

Link to comment
Share on other sites

I would n't use an INSERT  ... SELECT statement in this case. Just an normal insert with a couple of subqueries

INSERT INTO property_appointments (property_id, department_id, task_type_id, notes, priority_days) 
VALUES ( :property_id
         , (SELECT department_id FROM departments WHERE department = :deptname)
         , (SELECT task_type_id FROM task_Types WHERE task_type = :taskname)
         , :notes
         , 1 );

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.