I have two different tables and i decided to merge them into one table...
the birth table has
id, name, country, birthday_date, description, link
the death table has
id, name, country, death_date, description, link
and i want to merge them into a single table with the structure
id, name, country, bdate, ddate, description, link.
The link from each table has a unique value so i have to merge the tables using the link. I tried many queries but resulted in wrong results.
Both the birth and death table can have same names and some names may have either only birth or death date.
How can i merge them and updating a null date for a column that has no value on either tables?
#Create the new table
CREATE TABLE people (id INT, name VARCHAR(255), country CHAR(2), bdate DATE, ddate DATE, description TEXT, link VARCHAR(255));
# Populate it from the birth table
INSERT INTO people (id, country, bdate, description, link) SELECT id, country, bdate, description, link FROM birth;
# Fill in missing fields using the death table
UPDATE people, death SET people.id = death.id WHERE people.id IS NULL AND people.link = death.link;
UPDATE people, death SET people.name = death.name WHERE people.name IS NULL AND people.link = death.link;
# ..etc, repeated for each column
Is there any other query to insert data for all columns?
Why, is copying and pasting three times too much work? This is a one time thing, right?