Home » SQL & PL/SQL » SQL & PL/SQL » inserting data from one table to another using sql
inserting data from one table to another using sql [message #39463] Thu, 18 July 2002 06:31 Go to next message
mrweatherbee
Messages: 13
Registered: June 2002
Junior Member
Hi guys,

I'm having a little trying to get this sql statement right. basically i have four tables and need to fill a blank column in table1 with a value from table4. here's how the tables are set up:

table1(employeeid, division)
table2(employeeid, ssnum)
table3(ssnum, divisioncode)
table4(divisioncode, divisionname)

so table1 has employeeid filled out already for each row and division is blank. basically i need to fill the division column in table1 with the division name in table 4 for each row in table1. for example if the employeeid in the first row in table 1 is 0001, the sql statement needs to find employeeid 0001 in table 2, get his ssnum, go to table 3 and find the division code that matches that ssnumber and then go to table 4 and match that division code to the division name, and then insert that division name into the division column for employee 0001 in table 1 and then do the same thing for every row in table 1. hopefully that all made sense! :) anyways, if anyone could give me some help on how to write this statement it would be GREATLY appreciated! thank you so much

mr.w
Re: inserting data from one table to another using sql [message #39473 is a reply to message #39463] Thu, 18 July 2002 08:54 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
update t1
   set division = (select t4.divisionname
                     from t2, t3, t4
                    where t2.employeeid = t1.employeeid
                      and t3.ssnum = t2.ssnum
                      and t4.divisioncode = t3.divisioncode);
Previous Topic: & in pl/sql ????
Next Topic: How do I create a select with a value taken from a file?
Goto Forum:
  


Current Time: Fri Apr 26 13:53:17 CDT 2024