If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Multiple row update ina table from another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-04, 11:58
GKGN82 GKGN82 is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
Multiple row update ina table from another table

Hi,

I have the foll schema.

table1:
*P,A,B,C

table2:
*P,A,B,C

Consider the records in the table:
table1:
P A B C
1 x y n
2 x y n
3 x y n
4 p q y
5 p q n

table2:
P A B C
1 x y y
2 p q y

i need to update the field C in table1 with the filed C in table 2
where table1.A = table2.A and table1.B = table2.B.

the foll query is not working.
update table1 t1
set c=
(select t2.c
from table2 t2
where t1.A = t2.A
and t1.B = t2.B
)
where exists
(select t2.c
from table2 t2
where t1.A = t2.A
and t1.B = t2.B
)


pls help me
Reply With Quote
  #2 (permalink)  
Old 04-17-04, 12:43
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Can you describe "not working" in more detail? Based on the test data that you've posted, there is nothing for the query to do, but it should do nothing quite nicely.

If you change the values of table1.c to 'X' or something like that, then re-run your query, it should put you right back where you started.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On