List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:April 21 1999 5:28pm
Subject:Re: [Question] About 2 table in one database
View as plain text  
Yao Feng wrote:
> 
>   I think the manual of mysql is few to satisfy a newbie in sql.I have
> one question in this:
>   One DATABASE data;
>   include two TABLE log and ip;
>   What I want to do is:
>   update (or substitute) the TABLE log 's COLUMN url with TABLE ip 's
> COLUMN newip IF some condition happens(such as both TABLE 's COLUMN flag
> are same).
> 
>   Any advices to do it? It confused me for a few days.

Hi Yao

If you have a UNIQUE or PRIMARY KEY on log, you can do this:
1) CREATE a temporary table with all columns like log.
2) INSERT INTO 
	temp_log (column1, column2, ...., url) 
SELECT 
	log.colum1, log.column2, ..., ip.newip
FROM
	log, ip
WHERE
	log.flag=ip.flag

3) REPLACE INTO
	log
SELECT
	temp_log

4) DROP temp_log

You can hold temp_log for the next round and just delete the contents, if needed.

Tschau
Christian

Thread
[Question] About 2 table in one databaseYao Feng21 Apr
  • Re: [Question] About 2 table in one databaseThimble Smith21 Apr
  • Re: [Question] About 2 table in one databaseChristian Mack21 Apr