Re: Update statement syntax -- Please Help!!
Posted in 1999
On Fri, Oct 01, 1999 at 06:28:46PM +0000, Eugene Nechayev wrote: > In article <7t2rd4$8ie$1@nnrp1.deja.com>, > pbandaru@my-deja.com wrote: > > Hello All, > > > > Need a quick help with the update syntax. I am trying to update a > > column in one table with the values from another table. I am trying > the > > general SQL syntax that I know. But it does not work. > > > > Can some body please help in this. > > > > THe syntax I am using is > > > > UPDATE table1, table2 > > set table1.col1=table2.col2 > > where table1.col3=table2.col3 > > > > UPDATE table1 > SET table1.col1=(SELECT table2.col2 > FROM table2 > WHERE table1.col3=table2.col3) > > Regards, > Eugene Nechayev And if you don't want to get table1.col1 set to null when there are no data in table2.col3 with the same value as in table1.col3 you have to add: UPDATE table1 SET table1.col1=(SELECT table2.col2 FROM table2 WHERE table1.col3=table2.col3) WHERE table1.col3 IN (SELECT table2.col3 FROM table2) Best Regards, Octav -- Octav Chiriac Phone: (373) 2 22 99 67 NetInfo S.R.L. Fax: (373) 2 21 36 59 Chisinau (373) 2 22 84 88 Moldova, Republic of mailto:com@netinfo-moldova.com