mysql - Insert several datasets for several IDs -
i have table of users:
userid | user 1 martin 2 lilian 3 oliver
now have table:
dataid | userid | key | value
now need is:
select users user-table , insert several recrods in data-table:
i need combine these 2 querys:
insert `data` (`userid`, `key`, `value`) values (here_id_of_user, 'somekey', 10), values (here_id_of_user, 'otherkey', 20) select `userid` `users` ...
not sure understand want do, i'll assume want this:
insert data (userid,key,value) select userid,'somekey',10 users ... insert data (userid,key,value) select userid,'otherkey',20 users ...
if that's not want, you'll need bit more explicit...
update
if have data want insert each user in table, can use:
insert data (userid,key,value) select u.userid,dd.key,dd.value users u,default_data dd ...
if don't (and don't want store in table), can use;
insert data (userid,key,value) select userid,'some key',10 users ... union select userid,'other key',20 users ...
or (to avoid repetition of where
clause):
insert data (userid,key,value) select u.userid,dd.key,dd.value users u, ( select 'some key' key,10 data union select 'other key',20 ) dd ...
there more ways it.
Comments
Post a Comment