0

i am trying to add a select in an insert statement but one of my parameters is not part of the select and i d'ont know how to handle this. would you mind helping me please, thanks

what i want to achieve is :

  • inserting data into my table installs_workflows(install_id,action_id,order)
  • the first col (install_id) is fixed (already defined value i have in my code)
  • i want to gather the data for the two last columns in another select

i wanted to do something like this but i'm not sure it will work

insert into installs_workflows(install_id,action_id,order)
values("myIDhere", (select action,order from installs_actions where ostype=0))

let me know if you don't understand what i'm trying to achieve, thanks.

(in fact, for each result found in the SELECT statement, i want to insert them in the table installs_workflows with a specific install_id (that is the same)

thanks again

ps : or can i add a dmmy value in the select maybe ? this way i could do something like :

insert into installs_workflows(install_id,action_id,order)
select "MyID",action,order from installs_actions where ostype=0
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
olivierg
  • 728
  • 7
  • 26
  • 1
    You can still use it in the `select`, something like this: `insert into table (col1, col2) select 'myidhere', action from ...` – sgeddes Sep 11 '19 at 13:33
  • Possible duplicate of [Insert into ... values ( SELECT ... FROM ... )](https://stackoverflow.com/questions/25969/insert-into-values-select-from) – Alberto Moro Sep 11 '19 at 13:35

1 Answers1

1

Use a SELECT directly as

insert into installs_workflows(install_id,action_id,order)
select 'myIDhere', action,order 
from installs_actions 
where ostype = 0;
Ilyes
  • 14,640
  • 4
  • 29
  • 55
  • thanks, just noticed that i could specify any value in the select on purpose, will mark the answer as the right one when possible – olivierg Sep 11 '19 at 13:43