sql - Insert selected multiple records to a table from existing table with another value -


my first table

voter

userid  | lgdiv  --------------------    1     |   3    2     |   4    3     |   6    4     |   3    5     |   3 

in second table, both userid , elecid primary keys

voterelection

voterid | elecid | votertype| votingstatus --------------    1      |  1   | normal  | active    2      |  1   | normal  | active    3      |  3   | normal  | active 

i want insert selected rows of voter table voterelection table electionid, votertype , votingstatus. electionid, votertype , votingstatus same values selected items votertable.

userid of voter table voterid of voterelection table.

furthermore assume select users lgdiv 3 this

        select userid voter lgdiv=3 ; 

according data have given here select 3 records.

i want insert 3 records selected voter voterelection elecid, votertype , votingstatus. records elecid, votertype , voting status same.

assume select elecid =3 votertype='normal' , votingstatus='active' 3 records. after insert should this.

voterelection

voterid | elecid | votertype | votingstatus --------------------------------------------    1    |  1     | normal    | active    4    |  1     | normal    | active    5    |  1     | normal    | active 

this grab searching

insert voterelection (voterid)    select userid      voter     lgdiv = 3; 

how can include elecid, votertype , votingstatus ?

you can add values in select into:

insert voterelection (voterid, elecid, votertype, votingstatus)      select userid, 1, 'normal', 'active' voter lgdiv=3; 

you can change values 1, 'normal', 'active' whatever want.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -