You can include constants and functions on your select e.g.

insert into table1_archive select *,now(),'thisuser' from table1....

Of course, if you are using something like php or perl, then 'thisuser' could
just as easily be HTTP_AUTH_USER etc.

BD wrote:

> I have 2 tables, table1 and table1_archive. The archive table has identical
> columns as table1 except it has a few extra columns like a log_date,
> user_id. I would like to copy the corresponding columns from table1 to
> table1_archive. Sounds simple, right?
>
> Example:
> insert into table1_archive select * from table1 BY NAME where ....
>
> But this doesn't of course update the additional columns in the archive
> table so I would have to run a separate UPDATE statement after it to update
> those fields.
> But the insert into won't work since the 2 tables aren't exactly identical.
> The archive table has a couple of extra columns.
>
> I'm using PHP so the only solution I've come up with is to go through
> table1 and insert the rows into table1_archive row by row. I'm wondering if
> there isn't an easier way to do this, using preferably only 1 or 2 sql
> statements. I really wish there was a "BY NAME" clause so only the
> corresponding columns would be inserted from the other table.
>
> I suppose I could break the table1_archive up into 2 tables: table1_archive
> (identical columns to table1) and table1_archive_log that has the extra
> columns. But how do I link the 2 archive tables?
>
> Is there an easier way to do this rather than going row by row? TIA
>
> Brent
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to