What is the proper way to automatically create new tables based on values in another table? For instance, If table A has a column named city that contains different city values then I would need to create a new table based on each different city. Then all records with the respective city needs to be inserted into it's respective table. Also, if the city contains a space in the name it needs to be replaced with a an underscore. How could the same be done in MySQL?
In MS ACCESS I could accomplish this by:
Using A Select And Replace Query Named SELREP
SELECT table_A.column1, table_A.column2, table_A.city, Replace([city]," ","_") AS table_name_column FROM table_A;Create a Public Function MakeTableCity
Public Function MakeTableCity() DoCmd.SetWarnings False Dim db As Database Set db = Application.CurrentDb Dim distinctValues As DAO.Recordset Set distinctValues = db.OpenRecordset("SELECT table_name_column FROM SELREP GROUP BY table_name_column", dbOpenSnapshot) Do Until distinctValues.EOF DoCmd.RunSQL "SELECT * INTO " & distinctValues("table_name_column") & " FROM SELREP WHERE table_name_column ='" & distinctValues("table_name_column") & "'" distinctValues.MoveNext Loop DoCmd.SetWarnings True Set distinctValues = Nothing Set db = Nothing End Function