I have to iterate each row in my table User in MySQL. I need to create a new row Address for each iteration in User with some conditions described below.
I have 3 tables:
User: id, stuff, id_person, email
Person: id, stuff, id_address
Address: id, email
I need to create a new row in Address if the User.id_person is NOT NULL and that person.id_address IS NULL. I have to create the row with the same email that User.email. I have to do that for each row in User.
I tried to use MySQL cursor's but I do not know how to use them very well.
How can I do that? Is there any other way instead of using cursor's for that?
Thanks in advance.
EDIT: I have just realized that I also have to update person.id_address with the id of the address' row I have just created.
INSERT INTOw/ conditionals should suffice.