MySQL : Looping query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DougieC
    New Member
    • Jun 2007
    • 9

    #1

    MySQL : Looping query

    I am trying to insert records into a mastertable. The first field is auto-incrementing and therefore I am unable to insert all records at the same time. I have create the following code to insert one record in at a time.

    insert into `mastertable3`
    select ' ', 0301_2500.ssn, 0301_2500.vsssn , 0301_2500.name_ ind, 0301_2500.pay_g r_aa
    from time_period, Mastertable3 right join 0301_2500 on mastertable3.ss n = 0301_2500.SSN
    where (((if(mastertable3.s sn=0301_2500.ss n, 0, 1))=1))
    limit 1

    I am trying to create a loop to have this repeat continuously until the table 0301_2500 is exhausted, then switch to table 0302_2500, and etc...

    Any ideas?
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Mention the column names in INSERT statement except auto increment field e.g.

    Code:
    insert into `mastertable3` (field1,field2,field3,field4)
    select 0301_2500.ssn, 0301_2500.vsssn, 0301_2500.name_ind, 0301_2500.pay_gr_aa
    etc..

    Comment

    • DougieC
      New Member
      • Jun 2007
      • 9

      #3
      Didnt work. I believe the problem is that it can not generate multiple auto_incremente d numbers simultaneously. I would like to figure out how to do this with looping. Any links or walk throughs on looping would be helpful.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by DougieC
        Didnt work. ...
        What had you tried and what happened when you tried it?

        Comment

        Working...