Hey Guys
Hoping there are some SQL Gurus here. I need some assistance (MySQL specifically):
Context; I have 2 tables:
Table 1
--------
Customer_id | Entries
1 | 3
2 | 4
3 | 2
Basically, I need to duplicate the Customer_id in Table 2 for each Entry they have. Hence Table 2 should look like result set below after the insert:
Customer_id
1
1
1
2
2
2
2
3
3
How would I go about scripting this? Unfortunately I do not have the luxury of using another language (Like creating a Loop in PHP would have been perfect) as I have to do this via command line. Considering that there are 300K+ rows in Table1, manually typing INSERT INTO table2 VALUES X entries is impossible. And yes, I am aware that Table2 will most likely exceed a billion rows after the insert is complete (I have over 40Gb available).
Another issue I may have is that I will be doing this on a production server and may lock up Table1, but I will create a backup of the table first and work from the backup.
Thanks in advance
Hoping there are some SQL Gurus here. I need some assistance (MySQL specifically):
Context; I have 2 tables:
Table 1
--------
Customer_id | Entries
1 | 3
2 | 4
3 | 2
Basically, I need to duplicate the Customer_id in Table 2 for each Entry they have. Hence Table 2 should look like result set below after the insert:
Customer_id
1
1
1
2
2
2
2
3
3
How would I go about scripting this? Unfortunately I do not have the luxury of using another language (Like creating a Loop in PHP would have been perfect) as I have to do this via command line. Considering that there are 300K+ rows in Table1, manually typing INSERT INTO table2 VALUES X entries is impossible. And yes, I am aware that Table2 will most likely exceed a billion rows after the insert is complete (I have over 40Gb available).
Another issue I may have is that I will be doing this on a production server and may lock up Table1, but I will create a backup of the table first and work from the backup.
Thanks in advance