By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,415 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,415 IT Pros & Developers. It's quick & easy.

Update a thousand rows with specific value

P: 27
I would like to update thousand of Rows with its specific value

Suppose i have a table XYZ and ABC
XYZ contains Code,Name,RegDate And ABC also Contains the same
but the Value of RegDate of XYZ is Different than that of ABC..
i want to update XYZ's RegDate Value From the value of RegDate of table ABC
at once...

update XYZ set RegDate=
Feb 9 '10 #1
Share this Question
Share on Google+
5 Replies


ck9663
Expert 2.5K+
P: 2,878
How are the two tables related? What's the key that link them together?

Happy Coding!!!

~~ CK
Feb 9 '10 #2

Delerna
Expert 100+
P: 1,134
One of the simplest ways is
Expand|Select|Wrap|Line Numbers
  1. UPDATE xyx 
  2. set datereg=
  3. (
  4.    select datereg from abc 
  5.    where abc.Code=xyz.code 
  6.       and abc.name=xyz.Name
  7. )
  8.  
but as ck says, you don't indicate which fields are the key
Feb 10 '10 #3

OraMaster
100+
P: 135
Small modification in the posted SQL

UPDATE xyx
set datereg=
(
select datereg from abc
where abc.Code=xyz.code
and abc.name=xyz.Name
and abc.datereg <> xyz.datereg
)
Feb 25 '10 #4

ck9663
Expert 2.5K+
P: 2,878
Yet another version :)

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE x
  3. set datereg = a.datereg
  4. from XYZ x
  5. INNER JOIN ABC a on x.code = a.code and a.name = x.name and x.datereg <> a.datereg
  6.  
  7.  
Happy Coding!!!

~~ CK
Feb 25 '10 #5

P: 4
Update a set a.regdate=b.regdate from xyz a,abc b
where a.code=b.code and a.name=b.name and a.regdate<>b.regdate
Mar 11 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.