С SQL Server:
with t1 (rNO, id, fieldA, commonField) as
(
select row_number() over (partition by commonField order by id), id, fieldA, commonField
from a
),
t2 (rNO, id, fieldB, commonField) as
(
select row_number() over (partition by commonField order by id), id, fieldB, commonField
from b
)
select t1.id, t1.fieldA, t1.commonField, t2.fieldB
from t1
inner join t2 on t1.commonField = t2.commonField and t1.rNo = t2.rNo;
PS: В зависимости от ваших потребностей вы можете искать полное объединение:
with t1 (rNO, id, fieldA, commonField) as
(
select row_number() over (partition by commonField order by id), id, fieldA, commonField
from a
),
t2 (rNO, id, fieldB, commonField) as
(
select row_number() over (partition by commonField order by id), id, fieldB, commonField
from b
)
select coalesce(t1.id, t2.id) as id, t1.fieldA, coalesce(t1.commonField, t2.commonField) as commonField, t2.fieldB
from t1
full join t2 on t1.commonField = t2.commonField and t1.rNo = t2.rNo;