-2

i am running this query where in rel_branding there are more than 1 rows and i want to insert brandingid of every record in rel_branding_permission.

This is for PostgresSQL.

insert into rel_branding_permission (brandingid,permissionid) 
values((select brandingid from rel_branding), 404);

I want to insert this query in my DB as for all branding ids

Ankur _28
  • 7
  • 1

1 Answers1

0

You should be using an INSERT INTO ... SELECT here, something like this:

INSERT INTO rel_branding_permission (brandingid)
SELECT brandingid
FROM rel_branding
WHERE <some condition>

You would probably want to include more than one column in the insert into the rel_branding_permission table, and you may modify the above to fit your need by adding the additional columns to both the INSERT and the SELECT.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360