Home » SQL & PL/SQL » SQL & PL/SQL » extracting information from 2 different tables
extracting information from 2 different tables [message #227193] Tue, 27 March 2007 08:49 Go to next message
lisafitz
Messages: 10
Registered: November 2006
Junior Member
Hi currently i have 2 tables ....
The first table i am extracting information re department codes

What i want to do is if a dept_code = 820 than go to a diffent table and get the newer dept code from another field called dept_code2

select h.dept_code1
from hr_depart h
where h.dept_code1 in (select dept_code2 from table_2
where dept_code1 = '820')

thanks in Advance
Re: extracting information from 2 different tables [message #227267 is a reply to message #227193] Tue, 27 March 2007 15:53 Go to previous message
Ericle
Messages: 44
Registered: April 2006
Location: United States of America ...
Member

If I'm understanding you right, you could use this:

select t2.dept_code2
from   hr_depart hr, table_2 t2
where  hr.dept_code1 = '820'
and    hr.dept_code1 = t2.dept_code1


Actually, if all you are looking for is the dept_code2 column that matches up with the old dept_code1 of '820' then you just have to use this:

select dept_code2
from   table_2
where  dept_code1 = '820'


It just depends on exactly what you're doing. Is '820' the only deptartment code you're working with or is that just an example?

If you're just looking for all records that have new department codes in table_2, you could use this:

select t2.dept_code2
from   hr_depart hr, table_2 t2
where  hr.dept_code1 = t2.dept_code1



Eric

[Updated on: Tue, 27 March 2007 16:04]

Report message to a moderator

Previous Topic: FLAG incorrectly set for Feb leap year
Next Topic: ORA-00936: missing expression
Goto Forum:
  


Current Time: Sun Dec 04 13:06:57 CST 2016

Total time taken to generate the page: 0.08020 seconds