Hello,
I need help performing the following action on a table inside my database:
for every id (cal_id) that exists in my table I need to grab one piece of data from one column (cal_category) then delete all the other entries that have the same id and then create 5 all new entries with the category number previously found and new names in "cal_login" field.
If the id doesn't exist I can skip to the next id that exists.
In other words, for example, this:
5148 studio A 3
5148 Stephen A 3
5148 Marc A 3
5148 Lou A 3
5148 Fran A 3
5148 Eric A 3
5147 Eric A 1
5122 Fran D 2
needs to become this:
5148 studio A 3
5148 Stephen A 3
5148 Marc A 3
5148 Lou A 3
5148 Fran A 3
5148 Eric A 3
5148 studio A 3
5147 Eric A 1
5147 Stephen A 1
5147 Marc A 1
5147 Lou A 1
5147 Fran A 1
5147 studio A 1
5122 Eric D 2
5122 Stephen D 2
5122 Marc D 2
5122 Lou D 2
5122 studio D 2
5122 Fran D 2
Can anyone help me?
I am not proficient with MySQL but I sort of know that I can select the data I need like this:
SELECT cal_id, cal_category FROM webcal_entry_user
and I can insert the new lines like this (although I am not quite sure of this syntax):
INSERT INTO example (cal_id, cal_category) VALUES('studio', 'cal_category')
INSERT INTO example (cal_id, cal_category) VALUES('Marc', 'cal_category')
INSERT INTO example (cal_id, cal_category) VALUES('Fran', 'cal_category')
INSERT INTO example (cal_id, cal_category) VALUES('Eric', 'cal_category')
INSERT INTO example (cal_id, cal_category) VALUES('Lou', 'cal_category')
but I don't know how to put these things all together in one coherent MySQL query that will loop through all the IDs that exist in this table.
Thanks for your help.