[thelist] MYSQL merging multiple tables

Steve Bigelow steve.bigelow at tkcsb.com
Wed Sep 3 10:20:03 CDT 2008


Could you use a UNION to do this?

For example, assume you have columns COMMON_1, COMMON_2, and UNIQUE_1
(char(5)) in table 'A', columns COMMON_1, COMMON_2, and UNIQUE_2 (char(10))
in table 'B', and you want to put the results into table 'C'. Would
something like this work?

INSERT INTO C (COMMON_1, COMMON_2, UNIQUE_1, UNIQUE_2)
SELECT COMMON_1, COMMON_2, UNIQUE_1, '' AS UNIQUE_2 FROM A
UNION
SELECT COMMON_1, COMMON_2, '' AS UNIQUE_1, UNIQUE_2 FROM B

You should be able to use WHERE clauses on each SELECT statement if needed.

(Apologies if my syntax is off a bit -- I'm a T-SQL guy jumping into the
world of MySQL...)

Regards,

Steve Bigelow

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Jeremy Weiss
Sent: Wednesday, September 03, 2008 8:18 AM
To: thelist at lists.evolt.org
Subject: [thelist] MYSQL merging multiple tables

I have a database that contains several tables. Each table is updated once a
day from various sources. After they are updated, I'd like to merge them
into a single table. Most of the fields in each of the tables are the same,
but there are some differences. What would be the easiest way to go about
combining these tables into one?

Thanks,
Jeremy



-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 




More information about the thelist mailing list