You have no need to add a "modules" field to your main/users table. Just JOIN
on the tables -- that's what Relational Databases are for. INNER
or OUTER
joins should be used depending on your needs.
For example, this will return a user with their conditions. If the user doesn't have any conditions, it will return NULL for those fields, but it will still return the user:
SELECT *
FROM User U
LEFT JOIN Conditions C ON U.Id = C.User_ID
Good visual representation of joins
It depends of your volumetry but you can use a simple INSERT SELECT statement.
You old table:
mysql> desc old_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| fname | varchar(255) | YES | | NULL | |
| lname | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Imagine you want to replace fname by firstname, lname by lstname and add a birthdate field.
Create your new structure:
CREATE TABLE new_table (
id int(11),
firstname varchar(255),
lastname varchar(255),
birthdate DATETIME DEFAULT NULL
);
Now, transfert the old data in the new table, note that the new fields (here Birthdate) will be empty:
INSERT INTO new_table (id, firstname, lastname) SELECT id, fname, lname FROM old_table;
It's just a generic example, if you want for specific one, please add your tables structures in your question.
Max.
Edit for question "At what point would it be a good idea to do something else? ":
The INSERT SELECT statement locks (write lock) your table to enforce data consitency during operation. I can't answered to the question "at what point" it depends of your server, configs... But imagine your have a table with 1 Million rows, the operation could take some seconds, we'll say 4 seconds for example, so for 4 seconds, your users will not write in your table.
Best Answer
Find the position of the
/
character, take everything left of it, then doDISTINCT