List:General Discussion« Previous MessageNext Message »
From:Sasha Pachev Date:May 5 1999 5:16pm
Subject:Re: Update / Replace Syntax
View as plain text  
Dean wrote:
> 
> Hello,
> 
> I am very new to Mysql. I have searched several mailing list for the
> answers I need and read the manual but cannot find the answer to a very
> basic question........
> 
> I am using Mysql 3.22.20 and Redhat 5.2 with latest version of perl.
> 
> The problem I have is trying to update a table with data from another
> table.
> 
> Table1 is the main data table called products, are some of the fields
> (code,SUPPLIER,MAKE,price)
> 
> Table 2 is a temorary table where I insert a raw data file, manipulate it
> and when finished want to insert it into table 1(products) but only want to
> overwrite(replace) the price field if the code already exists.
> 
> I have tried the following to see if the code already exists, but get an
> error saying the client is out of memory
> 
> :--- SELECT * FROM products,table2 WHERE products.code<>table2.code ;
> I have also tried the following
> :--- SELECT * FROM products,table2 WHERE NOT products.code=table2.code ;
> 
> Can somebody please advise the best way to update 1table with the data from
> 2table
> 
>

Use 

  replace into my_table select ...

make sure to use unique keys. More details in the
manual.

-- 
Sasha Pachev
http://www.sashanet.com/ (home)
http://www.direct1.com/ (work)
Thread
Update / Replace SyntaxDean5 May
  • Re: Update / Replace SyntaxSasha Pachev5 May