Это использует синтаксис сервера sql, я уверен, что вы можете изменить при необходимости:
Сначала настройте пример данных:
declare @a table(purchase int,A_ID int,[type] int,market int,[group] int,rate decimal(5,2),[max] int,[min] int)
insert @a values (1,1,1,1,1,0.12,1000,500)
,(1,1,2,1,1,0.3,2000,1500)
,(0,1,3,1,1,0.2,5000,800)
,(0,1,4,1,1,0.6,8000,2800)
,(0,1,6,1,1,0.7,null,2800)
declare @b table(purchase int,A_ID int,[type] int,market int,[group] int,rate decimal(5,2),[max] int,[min] int)
insert @b values
(1,1,1,1,null,0.2,null,null)
,(1,1,2,1,null,null,5000,3000)
,(0,1,3,1,null,0.5,3000,1000)
,(0,1,5,1,null,0.4,3800,2000)
,(0,1,6,1,null,null,null,3000)
Затем запрос:
select coalesce(b.purchase,a.purchase) purchase,
coalesce(b.A_ID,a.A_ID) A_ID,
coalesce(b.[type],a.[type]) [type],
coalesce(b.market,a.market) market,
coalesce(b.rate,a.rate) rate,
coalesce(b.[max],a.[max]) [max],
coalesce(b.[min],a.[min]) [min]
from @a a
full outer join @b b on b.purchase=a.purchase and b.[type]=a.[type] and b.market=a.market
order by rate
Добавьте любую сортировку по вашему требованию.