select distinct top n *
from t1 inner join t2 on ... join t3 on ...
where ...
group by ... having ...
order by ... limit ... offset ...
update ... set ...
where...
select distinct top n *
from t1 inner join t2 on ... join t3 on ...
where ...
group by ... having ...
order by ... limit ... offset ...
update ... set ...
where...