[thelist] merging tables in mysql

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Fri Aug 20 12:07:14 CDT 2004


Hi Sarah,

	First off, I'd recommend not using SELECT * since it can be a
bit of a performance hit on higher-traffic sites.

	That said, you may be *required* to explicitly select the fields
for a UNION query, e.g.

 SELECT Field1, Field2 FROM Clients1
UNION
 SELECT Field1, Field2 FROM Clients2

HTH,

Peter

-----Original Message-----
From: thelist-bounces at lists.evolt.org On Behalf Of Sarah Sweeney

I'm working on a project building a Contact Management System which 
will, in effect, merge two existing systems. I've done a bunch of work 
with the databases (SQL Server and Access) to merge them into one 
(MySQL). Basically, what I've got now are two copies of each table, now 
sharing the exact same structure. I just need to be able to merge the 
copies into one single table. I tried this:
   CREATE TABLE Clients AS
     (SELECT * FROM Clients1
      UNION
      SELECT * FROM Clients2)
but I got a syntax error:
   ERROR 1064: You have an error in your SQL syntax.  Check the manual
   that corresponds to your MySQL server version for the right syntax to
   use near 'UNION
        SELECT * FROM Clients2)' at line 3
However, if I run the SELECT statement all by itself, it works fine. I 
assume this means that my UNION is not allowed in this instance. Any 
ideas on how I can merge my tables?

BTW, I am using MySQL version 4.0.16-standard.

TIA

-- 
Sarah Sweeney  ::  Web Developer & Programmer
Portfolio  ::  http://sarah.designshift.com
Blog  ::  http://hardedge.ca
Family  ::  http://geekjock.ca
-- 




More information about the thelist mailing list