declare @tab1 table (Name varchar(50),Pos varchar(50),Section varchar(50))
declare @tab2 table (ID varchar(50),Month2 varchar(50),Pos varchar(50),Section varchar(50))
insert into @tab1
select 'Jim','Sup','HD'
union
select 'Don ','Sup','SA'
union
select 'Rin ','Ast','SA'
union
select 'Boy ','Ast','HD'
insert into @tab2
select 'R01','Jan','Sup','SA'
union
select 'R02','Jan','Ast','SA'
union
select 'R03','Feb','Ast','HD'
union
select 'R04','Jan','Sup','HD'
--select * from @tab1
--select * from @tab2
select t2.*,t1.Name
from @tab1 t1
inner join @tab2 t2 on t2.Section = t1.Section and t1.Pos = t2.Pos
and t2.Month2 = 'Jan'
Выход:
ID Month2 Pos Section Name
R01 Jan Sup SA Don
R02 Jan Ast SA Rin
R04 Jan Sup HD Jim