kvijayhari — 2010-01-24T01:33:01-05:00 — #1
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?
dan_grossman — 2010-01-24T02:01:29-05:00 — #2
#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
kvijayhari — 2010-01-24T09:35:45-05:00 — #3
Is there any other query to insert data for all columns?
dan_grossman — 2010-01-24T16:34:27-05:00 — #4
Why, is copying and pasting three times too much work? This is a one time thing, right?