Mostafa90
Mostafa90

Reputation: 1706

Inner join of two table on three variable

I want to do an inner join between a table a and another table b which contain 2 columns, and I want the key_service from table a equal to the key service element of variable key_service from table b and also equal to the element of variable parent_key_service from table b too. I solve this by doing two inner join and doing an union all between my tables but I want to do it directly, is it possible ? thank you

proc sql;
   create table ca_m_service as
   select a.month_key, a.service_key, a.tot_revenue, a.TOT_REVENUE_DISCNT, a.euser_key, b.*
   from fr_dme.M_service_rev_by_euser_f  as a
   inner join code_remise_ass as b
     on a.service_key = b.service_key
   inner join code_remise_ass as c 
     on a.service_key = c.parent_service_key
   where a.month_key between 201504 and 201509;
quit;

Upvotes: 0

Views: 3391

Answers (1)

DomPazz
DomPazz

Reputation: 12465

You can use the AND logical statement in the join clause.

create table ca_m_service as
select a.month_key
     , a.service_key
     , a.tot_revenue
     , a.TOT_REVENUE_DISCNT
     , a.euser_key
     , b.*
from fr_dme.M_service_rev_by_euser_f  as a
   inner join 
     code_remise_ass as b 
   on    a.service_key = b.service_key
     and a.service_key = b.parent_service_key
where a.month_key between 201504 and 201509 ;

Upvotes: 1

Related Questions