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 #2467] Thu, 18 July 2002 06:40 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 #2487 is a reply to message #2467] Fri, 19 July 2002 09:30 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
It looks like my previous reply to this post was lost when the board was restored, so here it is again:

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: how to delete all the rows from a table?
Next Topic: Re: i want to print my name in triangle shape
Goto Forum:
  


Current Time: Wed Apr 24 11:00:31 CDT 2024