Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

joining two tables

Status
Not open for further replies.

tarunaray

Programmer
Joined
Apr 17, 2007
Messages
1
Location
US
Hi,
Hi,
I appreciate if anyone help me out to solve my problem :
There are two table like Table 1 and Table 2:
Table 1 contain coloms like :
Emp_id
Spl_event_date ( spl training given to employee)
Name
Address
Table 2 contain :
Emp_id
Date_sal_revised
Revised_Monthly_Salary

REQUIREMENT :
Joining Table2 to Table1 on Emp_Id so that Table 1 carries one additional column SALARY like follows :

Result Table1 :

Emp_id
Spl_Event_date
Name
Address
salary

CONDITION :

Where selected SALARY from Table2 is EQUAL TO OR FIRST DATE'S GREATER THAN Spl_Event_date of table1

 
Where selected SALARY from Table2 is EQUAL TO OR FIRST DATE'S GREATER THAN Spl_Event_date of table1.

Didn't get the meaning of the above sentence. Can you repost your question more clearly?

Thanks,
Pramod
 
I answered this question on Teradata Discussion Forums a few days ago.
This answer could help other users on this forum...

select T1.EMP_ID
, T1.SPL_EVENT_DATE
, T1.NAME
, T1.ADRESS
, T2.REVISED_MONTHLY_SALARY
from TABLE_1 as T1
inner join
TABLE_2 as T2
on T1.EMP_ID = T2.EMP_ID
where exists ( select 1
from TABLE_2 as T
where T2.EMP_ID = T.EMP_ID
and T1.SPL_EVENT_DATE <= T.DATE_SAL_REVISED
having T2.DATE_SAL_REVISED = min(T.DATE_SAL_REVISED)
)
;

or

select T1.EMP_ID
, T1.SPL_EVENT_DATE
, T1.NAME
, T1.ADRESS
, T2.REVISED_MONTHLY_SALARY
from TABLE_1 as T1
inner join
TABLE_2 as T2
on T1.EMP_ID = T2.EMP_ID
and T1.SPL_EVENT_DATE <= T2.DATE_SAL_REVISED
qualify T2.DATE_SAL_REVISED = min(T2.DATE_SAL_REVISED) over(partition by T2.EMP_ID)
;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top