Merging Two Tables in Mysql

27
Oct
0

Ok, I had two mailing lists I needed to add together (minus duplicates of coarse)

 

first make sure both talbes have the same fields (one had “last_name” and “first_name” fields while the other had just “name”)

 

UPDATE coo_mailing_list SET name = CONCAT(first_name, ‘ ‘, last_name);

 

bam!!! coo_mailing_list has a name field with first and last names in it.

Next merge the two tables into a new table

CREATE TABLE new_mailing_list SELECT DISTINCT * FROM (SELECT name, email FROM mailing_list UNION ALL SELECT name,email FROM coo_mailing_list) sq;

 

add a primary key field and set to auto increment and rename the old and mailing lists  tables and your

your done!

Filed under: mysql
Comments (0) Trackbacks (0)

No comments yet.

Sorry, the comment form is closed at this time.