declare @tA table (id int, nameA nvarchar(100))
declare @tB table (id int, nameB nvarchar(100), pos int IDENTITY(1,1), shift int)
declare @tC table (id int, nameC nvarchar(100), pos int IDENTITY(1,1), shift int)
insert into @tA(id, nameA)
select 1, 'Foot' union all
select 2, 'Head' union all
select 3, 'Leg'
insert into @tB(id, nameB)
select 1, 'aaa' union all
select 1, 'bbb' union all
select 2, 'ccc' union all
select 2, 'ddd'
insert into @tC(id, nameC)
select 1, 'xxx' union all
select 1, 'yyy' union all
select 1, 'zzz' union all
select 2, 'www'
update b
set shift = pos - q.minPos
from @tB b
join (
select
MIN(pos) as minPos,
id
from @tB
group by id
) q on q.id = b.id
update c
set shift = pos - q.minPos
from @tC c
join (
select
MIN(pos) as minPos,
id
from @tC
group by id
) q on q.id = c.id
select
a.id,
a.nameA,
b.nameB,
c.nameC
from @tC c
full join @tB b on c.id = b.id and c.shift = b.shift
right join @tA a on a.id = ISNULL(b.id, c.id)