Append one table to another?

2005-10-11 Thread Brian Dunning
How do I append one table's contents to another? Both have identical  
structure. Problem is I don't have shell access, only phpAdmin or a  
PHP file I write  upload myself.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Paul DuBois

At 7:57 -0700 10/11/05, Brian Dunning wrote:
How do I append one table's contents to another? Both have identical 
structure. Problem is I don't have shell access, only phpAdmin or a 
PHP file I write  upload myself.


If the tables are identical, you can do this:

INSERT INTO t2 SELECT * FROM t1;

--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Peter Brawley

Brian

How do I append one table's contents to another? Both have
identical  structure. Problem is I don't have shell access, only
phpAdmin or a  PHP file I write  upload myself.

How about

 INSERT into tbl1 SELECT * FROM tbl2

PB






--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.14/128 - Release Date: 10/10/2005


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Jose Miguel Pérez
Hi Brian!

 How do I append one table's contents to another? Both have identical
 structure. Problem is I don't have shell access, only phpAdmin or a
 PHP file I write  upload myself.

You can do it this way:

INSERT INTO table1 SELECT * FROM table2;

If you need to have more control over what is copied, you can add a
WHERE clause in the SELECT above. Also, you can restrict how it is done by
adding some fields restrictions:

INSERT INTO table1 (field1, field2)
SELECT field1, field FROM table2
WHERE field1 = Some value

Cheers,
Jose Miguel.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Brian Dunning

INSERT into tbl1 SELECT * FROM tbl2


Thanks to both of you, but this is not working. Since one of the  
fields is a primary key that's duplicated in both tables (both tables  
have records numbered 1, 2, 3...), it won't allow the duplicate  
entries. Fortunately I do not need those primary key values to be  
preserved - it's OK to insert the new records with auto-increment  
values where the target table left off. So I tried:


insert into target_table select `field1`,`field2` from original_table;

and I listed all but the auto-increment field. This doesn't work  
either, it just says to check my syntax, but I can't see a problem.  
Any ideas?


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Paul DuBois

At 9:00 -0700 10/11/05, Brian Dunning wrote:

INSERT into tbl1 SELECT * FROM tbl2


Thanks to both of you, but this is not working. Since one of the 
fields is a primary key that's duplicated in both tables (both 
tables have records numbered 1, 2, 3...), it won't allow the 
duplicate entries. Fortunately I do not need those primary key 
values to be preserved - it's OK to insert the new records with 
auto-increment values where the target table left off. So I tried:


insert into target_table select `field1`,`field2` from original_table;

and I listed all but the auto-increment field. This doesn't work 
either, it just says to check my syntax, but I can't see a problem. 
Any ideas?


The manual is your friend:

http://dev.mysql.com/doc/mysql/en/insert-select.html

--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Append one table to another?

2005-10-11 Thread Brian Dunning

On Oct 11, 2005, at 8:24 AM, Jose Miguel Pérez wrote:


INSERT INTO table1 (field1, field2)
SELECT field1, field FROM table2


Jose's solution worked perfectly. Thanks everyone, sorry for being so  
dense today.  :)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]