insert using select

Discussion in 'Databases' started by daboss, Nov 9, 2006.

  1. #1
    say i have table_1 with fields a, b & c
    and i have table_2 with fields a, b & d

    i want to populate fields a & b of table 2 from records in table 1. in this case, i use:

    INSERT INTO table_2 (a, b)
    SELECT table_1.a, table_1.b FROM table_1

    but if i do the above, field d of table_2 will always be blank.

    how do i solve the problem if i want to populate field d of table_2 with a constant value of "hello" ?

    thanks for your time.
     
    daboss, Nov 9, 2006 IP
  2. Angelus

    Angelus Well-Known Member

    Messages:
    1,622
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    138
    #2
    Why would you like to do that?

    p.l.u.r.
     
    Angelus, Nov 9, 2006 IP
  3. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #3


    INSERT INTO table_2 (a, b, d)
    SELECT table_1.a, table_1.b, "hello" FROM table_1
     
    SoKickIt, Nov 9, 2006 IP
    daboss likes this.
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yeah... thanks! i just found out from a programmer friend... :D

    thanks!
     
    daboss, Nov 9, 2006 IP