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 > Database Server Software > Informix > How do I update records in one table based on values in another table ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-05, 12:01
InformixDan InformixDan is offline
Registered User
 
Join Date: Dec 2004
Posts: 5
Question How do I update records in one table based on values in another table ?

I have a Hold table where we load customer information (id#, address, etc) from a text file and would like to load that data into our Master table.

My problem is this.

1. The column names are different in the two tables.
2. The Master table has extra columns and are in a different order than the Hold table.


I can see using the UPDATE command, but how do I make sure the column data in the Hold table gets loaded into the right column data in the Master since they are in a different order ?

Would I use the WHERE command and specify COLUMN A in the Hold table equals COLUMN B in the Master ?

Thanks in advance from what probably is a novice question.
Reply With Quote
  #2 (permalink)  
Old 10-04-05, 12:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
which database?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-04-05, 12:06
InformixDan InformixDan is offline
Registered User
 
Join Date: Dec 2004
Posts: 5
It's an Informix SQL database.
Reply With Quote
  #4 (permalink)  
Old 10-04-05, 12:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
that would've been my first guess

the reason i ask is that there isn't a standard sql way to do this, and this is the standard sql forum

therefore, let's move this thread to the informix forum and see what we get
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-04-05, 14:50
June C. Hunt June C. Hunt is offline
Registered User
 
Join Date: Feb 2005
Posts: 43
There isn't a lot of detail about the tables involved, but you can test something like this to see if it will get you what you need:

UPDATE mastertbl SET
mstr_addr = (SELECT addr FROM holdtbl WHERE id = mstr_no),
mstr_city = (SELECT city FROM holdtbl WHERE id = mstr_no)
WHERE mstr_no IN (SELECT id FROM holdtbl);

I believe this covers most of your concerns (i.e. different column names, the order of the columns does not matter, the number of columns may differ between the two tables).

HTH.
Reply With Quote
  #6 (permalink)  
Old 10-04-05, 15:08
InformixDan InformixDan is offline
Registered User
 
Join Date: Dec 2004
Posts: 5
Thumbs up

Quote:
Originally Posted by June C. Hunt
There isn't a lot of detail about the tables involved, but you can test something like this to see if it will get you what you need:

UPDATE mastertbl SET
mstr_addr = (SELECT addr FROM holdtbl WHERE id = mstr_no),
mstr_city = (SELECT city FROM holdtbl WHERE id = mstr_no)
WHERE mstr_no IN (SELECT id FROM holdtbl);

I believe this covers most of your concerns (i.e. different column names, the order of the columns does not matter, the number of columns may differ between the two tables).

HTH.
Thank you. I appreciate the response and will try it out.


Quote:
Originally Posted by r937
that would've been my first guess
Reply With Quote
  #7 (permalink)  
Old 10-05-05, 10:59
InformixDan InformixDan is offline
Registered User
 
Join Date: Dec 2004
Posts: 5
Thumbs up

It worked ! Now I know what to do if I run into a similiar situation. Thank you for your help.
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