This is a discussion on Populating 3 tables from 1 record within the MySQL forums, part of the Database Server Software category; --> Hi everyone, I'm trying to populate 3 tables from 1 record, Not sure if I named it right, here's ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi everyone, I'm trying to populate 3 tables from 1 record, Not sure if I named it right, here's an explanation of what I wanted to happen Record 1: field1| field2| field3| field4| field5| field6| field7| from this record, I would like to make these 3 tables Table 1 field1| field4| field6 Table 2 field2| field3| field5| Table 3 field7| A complication is that there's no primary key to the original table. Is there any way to do this? Thank you for any help you can provide |
| |||
| "lyonnyte" <lyonnyte@gmail.com> schreef in bericht news:1186771323.329452.184340@i13g2000prf.googlegr oups.com... > Hi everyone, > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > right, here's an explanation of what I wanted to happen > > Record 1: > field1| field2| field3| field4| field5| field6| field7| > > from this record, I would like to make these 3 tables > Table 1 > field1| field4| field6 > > Table 2 > field2| field3| field5| > > Table 3 > field7| > > A complication is that there's no primary key to the original table. > > Is there any way to do this? > > Thank you for any help you can provide > INSERT into table1 SELECT field1, field4, field6 FROM table INSERT into table2 SELECT field2, field3, field5 FROM table INSERT into table3 SELECT field7 FROM table i dont get you're 'problem' with no primary key...... |
| |||
| On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: > "lyonnyte" <lyonn...@gmail.com> schreef in berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... > > > > > > > Hi everyone, > > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > > right, here's an explanation of what I wanted to happen > > > Record 1: > > field1| field2| field3| field4| field5| field6| field7| > > > from this record, I would like to make these 3 tables > > Table 1 > > field1| field4| field6 > > > Table 2 > > field2| field3| field5| > > > Table 3 > > field7| > > > A complication is that there's no primary key to the original table. > > > Is there any way to do this? > > > Thank you for any help you can provide > > INSERT into table1 SELECT field1, field4, field6 FROM table > > INSERT into table2 SELECT field2, field3, field5 FROM table > > INSERT into table3 SELECT field7 FROM table > > i dont get you're 'problem' with no primary key......- Hide quoted text - > > - Show quoted text - My main problem with no primary key is that I would not be able to tell which record in table1 corresponds to records in table2. |
| |||
| On Aug 10, 1:12 pm, lyonnyte <lyonn...@gmail.com> wrote: > On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: > > > > > > > "lyonnyte" <lyonn...@gmail.com> schreef in berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... > > > > Hi everyone, > > > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > > > right, here's an explanation of what I wanted to happen > > > > Record 1: > > > field1| field2| field3| field4| field5| field6| field7| > > > > from this record, I would like to make these 3 tables > > > Table 1 > > > field1| field4| field6 > > > > Table 2 > > > field2| field3| field5| > > > > Table 3 > > > field7| > > > > A complication is that there's no primary key to the original table. > > > > Is there any way to do this? > > > > Thank you for any help you can provide > > > INSERT into table1 SELECT field1, field4, field6 FROM table > > > INSERT into table2 SELECT field2, field3, field5 FROM table > > > INSERT into table3 SELECT field7 FROM table > > > i dont get you're 'problem' with no primary key......- Hide quoted text - > My main problem with no primary key is that assuming I would have other records, I would not be able to > tell which record in table1 corresponds to records in table2.- Hide quoted text - Edited my statement. |
| |||
| "lyonnyte" <lyonnyte@gmail.com> schreef in bericht news:1186777178.026026.23950@q4g2000prc.googlegrou ps.com... > On Aug 10, 1:12 pm, lyonnyte <lyonn...@gmail.com> wrote: >> On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: >> >> >> >> >> >> > "lyonnyte" <lyonn...@gmail.com> schreef in >> > berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... >> >> > > Hi everyone, >> >> > > I'm trying to populate 3 tables from 1 record, Not sure if I named it >> > > right, here's an explanation of what I wanted to happen >> >> > > Record 1: >> > > field1| field2| field3| field4| field5| field6| field7| >> >> > > from this record, I would like to make these 3 tables >> > > Table 1 >> > > field1| field4| field6 >> >> > > Table 2 >> > > field2| field3| field5| >> >> > > Table 3 >> > > field7| >> >> > > A complication is that there's no primary key to the original table. >> >> > > Is there any way to do this? >> >> > > Thank you for any help you can provide >> >> > INSERT into table1 SELECT field1, field4, field6 FROM table >> >> > INSERT into table2 SELECT field2, field3, field5 FROM table >> >> > INSERT into table3 SELECT field7 FROM table >> >> > i dont get you're 'problem' with no primary key......- Hide quoted >> > text - > >> My main problem with no primary key is that assuming I would have other >> records, I would not be able to >> tell which record in table1 corresponds to records in table2.- Hide >> quoted text - > > Edited my statement. > no, you where "I'm trying to populate 3 tables from 1 record,"..... you should DEFINE how you want the relatie between table1 and table2 to be, i do not know your data, so i'm even more in the dark than you are..... |
| |||
| On Aug 10, 1:34 pm, "Luuk" <l...@invalid.lan> wrote: > "lyonnyte" <lyonn...@gmail.com> schreef in berichtnews:1186777178.026026.23950@q4g2000prc.goo glegroups.com... > > > > > On Aug 10, 1:12 pm, lyonnyte <lyonn...@gmail.com> wrote: > >> On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: > > >> > "lyonnyte" <lyonn...@gmail.com> schreef in > >> > berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... > > >> > > Hi everyone, > > >> > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > >> > > right, here's an explanation of what I wanted to happen > > >> > > Record 1: > >> > > field1| field2| field3| field4| field5| field6| field7| > > >> > > from this record, I would like to make these 3 tables > >> > > Table 1 > >> > > field1| field4| field6 > > >> > > Table 2 > >> > > field2| field3| field5| > > >> > > Table 3 > >> > > field7| > > >> > > A complication is that there's no primary key to the original table. > > >> > > Is there any way to do this? > > >> > > Thank you for any help you can provide > > >> > INSERT into table1 SELECT field1, field4, field6 FROM table > > >> > INSERT into table2 SELECT field2, field3, field5 FROM table > > >> > INSERT into table3 SELECT field7 FROM table > > >> > i dont get you're 'problem' with no primary key...... > > >> My main problem with no primary key is that assuming I would have other > >> records, I would not be able to > >> tell which record in table1 corresponds to records in table2. > > no, you where "I'm trying to populate 3 tables from 1 record,"..... > > you should DEFINE how you want the relatie between table1 and table2 to be, > i do not know your data, so i'm even more in the dark than you are..... If every row from the original table is going to become one row in each of the three new tables; i,e. tableA is becoming table1, table2, and table3, and there's a 1:1 relationship between table1, table2, and table3 (and tableA); the easiest thing to do would be to add an auto-sequence column to tables 1, 2 and 3. So long as you insert to tables 1, 2 and 3 at the same time, or in the same order, they each should get the same sequence number, and can be joined at any time based on that column. If the relationship is NOT 1:1, e.g., you expect, for example, sometimes field7 is null and you don't want null rows in table3, then just go ahead and insert a null field to keep the auto-sequence in sync, then delete all the rows where field7 is null once completed. The sequence won't change after the row has been inserted. If the relationship is NOT 1:1, e.g., it's a 1:many relationship between table1 and table2, such as table1 is the "master" and table2 is the "detail", then you'll have to think of something else. |
| |||
| On Aug 10, 1:12 pm, lyonnyte <lyonn...@gmail.com> wrote: > On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: > > > > > "lyonnyte" <lyonn...@gmail.com> schreef in berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... > > > > Hi everyone, > > > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > > > right, here's an explanation of what I wanted to happen > > > > Record 1: > > > field1| field2| field3| field4| field5| field6| field7| > > > > from this record, I would like to make these 3 tables > > > Table 1 > > > field1| field4| field6 > > > > Table 2 > > > field2| field3| field5| > > > > Table 3 > > > field7| > > > > A complication is that there's no primary key to the original table. > > > > Is there any way to do this? > > > > Thank you for any help you can provide > > > INSERT into table1 SELECT field1, field4, field6 FROM table > > > INSERT into table2 SELECT field2, field3, field5 FROM table > > > INSERT into table3 SELECT field7 FROM table > > > i dont get you're 'problem' with no primary key......- Hide quoted text - > > > - Show quoted text - > > My main problem with no primary key is that I would not be able to > tell which record in table1 corresponds to records in table2. So, at present you have no way of selecting a particular row from the master table aside from selecting on a particular field, which may return more than one row if there are duplicate entries in that field? Since, because of this, you are going to have to iterate through the entire table to create the records you want to create, why not, at the same time, add a unique id field to the master table and populate it in the process. Then you could create your additional tables as well as a linking table to track the relationship between all records. I normally work with php, a language that interacts with mysql when I am dealing with mysql data. If you are doing this, which is likely, you might be able to find a simple solution in that language to what you are trying to do. It is hard to suggest as you have not described what you are trying to accomplish by creating these tables. It might not even be necessary to create these tables. You might be able to work off of the data in the master table alone. --Kenoli |
| ||||
| On Aug 12, 8:45 am, Kenoli <kenol...@gmail.com> wrote: > On Aug 10, 1:12 pm,lyonnyte<lyonn...@gmail.com> wrote: > > > > > On Aug 10, 12:32 pm, "Luuk" <l...@invalid.lan> wrote: > > > > "lyonnyte" <lyonn...@gmail.com> schreef in berichtnews:1186771323.329452.184340@i13g2000prf.g ooglegroups.com... > > > > > Hi everyone, > > > > > I'm trying to populate 3 tables from 1 record, Not sure if I named it > > > > right, here's an explanation of what I wanted to happen > > > > > Record 1: > > > > field1| field2| field3| field4| field5| field6| field7| > > > > > from this record, I would like to make these 3 tables > > > > Table 1 > > > > field1| field4| field6 > > > > > Table 2 > > > > field2| field3| field5| > > > > > Table 3 > > > > field7| > > > > > A complication is that there's no primary key to the original table. > > > > > Is there any way to do this? > > > > > Thank you for any help you can provide > > > > INSERT into table1 SELECT field1, field4, field6 FROM table > > > > INSERT into table2 SELECT field2, field3, field5 FROM table > > > > INSERT into table3 SELECT field7 FROM table > > > > i dont get you're 'problem' with no primary key......- Hide quoted text - > > > > - Show quoted text - > > > My main problem with no primary key is that I would not be able to > > tell which record in table1 corresponds to records in table2. > > So, at present you have no way of selecting a particular row from the > master table aside from selecting on a particular field, which may > return more than one row if there are duplicate entries in that field? > > Since, because of this, you are going to have to iterate through the > entire table to create the records you want to create, why not, at the > same time, add a unique id field to the master table and populate it > in the process. Then you could create your additional tables as well > as a linking table to track the relationship between all records. > > I normally work with php, a language that interacts with mysql when I > am dealing with mysql data. If you are doing this, which is likely, > you might be able to find a simple solution in that language to what > you are trying to do. It is hard to suggest as you have not > described what you are trying to accomplish by creating these > tables. It might not even be necessary to create these tables. You > might be able to work off of the data in the master table alone. > > --Kenoli Thanks all, I added an auto increment field in the master table and created a linking table to track relationships. |