1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    Insert data to joining table SQL

    Hi, I'm confusing about the way to insert data to SQL. I have two tables like this:

    Table 1
    ID Message
    1 A
    2 B

    Table 2
    ID Reply
    1 i
    2 ii
    3 iii
    4 iv

    and I join two tables to be

    ID Reply Message
    1 i A
    2 ii A
    3 iii A
    4 iv B

    For one message could have multiple replies. Now I have a data like this:

    Message = [A,B]
    Reply = [i,ii,iii,iv] *This is the just automatic order in the list but the actual data I need should be reply[i,ii,ii] for message A, reply[iv] for message B.

    How can I insert these data properly in the join table? For example like:

    con.execute("INSERT INTO Table1(Message) VALUES(%s),Message[i]")
    con.execute("INSERT INTO Table2(Reply) VALUES(%s),Reply[i]")
    <<< This should be Reply[i,ii,iii]

    #Insert Message A first, and insert all replies in A. Then insert the message B and all replies for B.
    Last edited by MynE; April 23rd, 2013 at 03:15 PM.

IMN logo majestic logo threadwatch logo seochat tools logo