Home » RDBMS Server » Server Administration » Update query
Update query [message #372620] Wed, 28 February 2001 15:30 Go to next message
Dean
Messages: 34
Registered: August 2000
Member
I have two tables, a big and a small one. I want to write a query that updates a given field in the big table with one from the small table, but does not update the field if there is no match. Right now my query puts nulls in the big table if there is not a match.
This should be very easy to do. Any suggestions?
Re: Update query [message #372624 is a reply to message #372620] Wed, 28 February 2001 16:21 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
update big b
set b.col1 = (select a.col1 from small a
where a.joincol = b.joincol)
where b.joincol in (select c.joincol from small c);
Re: Update query [message #372625 is a reply to message #372620] Wed, 28 February 2001 16:22 Go to previous messageGo to next message
Joachim Lindner
Messages: 30
Registered: February 2001
Member
I'm not sure if I got you right, but this should help you ...

update big
set col = (
select col
from small
where small.pk = big.pk
);
Re: Update query [message #372628 is a reply to message #372620] Thu, 01 March 2001 03:51 Go to previous message
Joachim Lindner
Messages: 30
Registered: February 2001
Member
Sorry ... just checked my proposal and understand your problem now. Andrew's proposal does the job.
Previous Topic: how to select picture from a table?
Next Topic: To find number of occurences of a character in a string.
Goto Forum:
  


Current Time: Sat Jun 01 02:37:51 CDT 2024