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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.