select coalesce(r.id_digitalware, w.id)
from wares w left join
relations r
on r.id_digitalware = w.id
order by coalesce(r.id_usualware, w.id),
(w.itemtype = 'usual') desc;
select w2.*
from wares w left join
relations r
on r.id_digitalware = w.id left join
wares w2
on w2.id = coalesce(r.id_digitalware, w.id)
order by coalesce(r.id_usualware, w.id),
(w.itemtype = 'usual') desc;