Joining two tables

UDA
Enthusiast

Joining two tables

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

2 REPLIES
Enthusiast

Re: Joining two tables

Something like that ?

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)
;
Enthusiast

Re: Joining two tables

Thank you very much