how to loop and insert records

  • i have 3 tables like so below:

    table -A

    pid mid

    --- ----

    1 7

    2 29

    table -B

    sid pid mid

    --- --- ---

    1 1 7

    2 1 7

    3 2 29

    table -C

    sid toy

    --- ---

    1 car

    2 ball

    3 toy phone

    what i want is to loop through table A and C and add values sid,pid and mid into table -B

    column sid,pid and mid in table -B isn't auto incremented

    Any ideas and thanks in advance

  • Hi Patrick,

    I'm not sure you'd need to use a loop. Would a cross join not work?

    select sid, pid, mid

    from testA, TestC

  • In your example, what values did you use from table A and table C to generate table B?

  • Patrick Ige (4/1/2008)


    i have 3 tables like so below:

    table -A

    pid mid

    --- ----

    1 7

    2 29

    table -B

    sid pid mid

    --- --- ---

    1 1 7

    2 1 7

    3 2 29

    table -C

    sid toy

    --- ---

    1 car

    2 ball

    3 toy phone

    what i want is to loop through table A and C and add values sid,pid and mid into table -B

    column sid,pid and mid in table -B isn't auto incremented

    Any ideas and thanks in advance

    Patrick,

    what is the relation between A and C table

    if you do cross join you will get cortesan product records. check your resulted table

    shamsudheen

  • thanks guys all fixed using cross joins

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

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