简体   繁体   中英

Insert multiple rows based off condition

I am trying to insert multiple rows where each row has the same environment_id , however, it has different property_id . Something similar to the following:

INSERT INTO appserver_prop (environment_id, property_id)
VALUES (497, select property_id from prop_info where property_name like '%CPNIB%')

Just use :

insert into appserver_prop(environment_id, property_id)
select 497, property_id from prop_info where property_name like '%CPNIB%'

you don't need values clause, since you're not trying to insert a single record in SQL but multiple record set instead.

I think you want insert . . . select insert . . . select insert . . . select :

insert into appserver_prop (environment_id, property_id)
    select 497, property_id
    from prop_info
    where property_name like '%CPNIB%';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM