Destramic Posted October 8, 2018 Share Posted October 8, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/307768-select-and-insert/ Share on other sites More sharing options...
Barand Posted October 8, 2018 Share Posted October 8, 2018 Why are you in a position where the department and task_type ids are not known? Are you passing the names from an input form instead of the ids? Quote Link to comment https://forums.phpfreaks.com/topic/307768-select-and-insert/#findComment-1561446 Share on other sites More sharing options...
Barand Posted October 8, 2018 Share Posted October 8, 2018 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/307768-select-and-insert/#findComment-1561448 Share on other sites More sharing options...
Destramic Posted October 8, 2018 Author Share Posted October 8, 2018 i can pass the relevant ID's over infact, i don't know what i didnt do that instead of complicating things! the simpliest ways are always the best. thank you for the insight on how i could of done the query also. Quote Link to comment https://forums.phpfreaks.com/topic/307768-select-and-insert/#findComment-1561454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.