Insert values from table 1 to table 2

  • I HAVE TWO TABLE VOTERID and Deathtable

    Voter id table has the following field

    ISNID, Name,City,Alive

    I have attached the voterid table

    I wanted to extract the value from voterid where alive='NO'

    and add it into deathtable if not exists... if already exists leave it..

    I have used the below query:

    INSERT INTO DEATHTABLE (ISNID)

    SELECT ISNID FROM VOTERID WHERE ALIVE='NO' WHERE ISNID NOT IN (SELECT ISNID FROM DEATHTABLE)

    i am getting the below error.

    Incorrect syntax near the keyword 'WHERE'.

    Where my query gets errror... please help me...

  • Hi Write like ---

    INSERT INTO DEATHTABLE (ISNID)

    SELECT ISNID FROM

    VOTERID WHERE ALIVE='NO'

    AND ISNID NOT IN (SELECT ISNID FROM DEATHTABLE)

  • Thanks... i'll try this and let you know...

  • INSERT INTO DEATHTABLE (ISNID)

    SELECT d.ISNID FROM VOTERID v

    LEFT JOIN DEATHTABLE d

    ON d.ISNID=v.ISNID

    WHERE v.ALIVE='NO'

    and s.ISNID is null

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply