472,119 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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_gr_aa
from time_period, Mastertable3 right join 0301_2500 on mastertable3.ssn = 0301_2500.SSN
where (((if(mastertable3.ssn=0301_2500.ssn, 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?
Jul 10 '07 #1
3 2115
mwasif
802 Expert 512MB
Mention the column names in INSERT statement except auto increment field e.g.

Expand|Select|Wrap|Line Numbers
  1. insert into `mastertable3` (field1,field2,field3,field4)
  2. select 0301_2500.ssn, 0301_2500.vsssn, 0301_2500.name_ind, 0301_2500.pay_gr_aa
  3. etc..
Jul 10 '07 #2
Didnt work. I believe the problem is that it can not generate multiple auto_incremented numbers simultaneously. I would like to figure out how to do this with looping. Any links or walk throughs on looping would be helpful.
Jul 10 '07 #3
r035198x
13,262 8TB
Didnt work. ...
What had you tried and what happened when you tried it?
Jul 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Benjamin Dickgießer | last post: by
13 posts views Thread by aaron | last post: by
6 posts views Thread by Xenophobe | last post: by
1 post views Thread by Nick | last post: by
3 posts views Thread by xoinki | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.