select v.item_no, max(v.opm_kg), max(v.odm_kg)
from
(
select m.ITEM_NO, mic.SEGMENT1 opm_kg, ” odm_kg
from apps.gmi_item_categories_v1 gic,
apps.mtl_categories_vl mic,
apps.ic_item_mst m
where mic.STRUCTURE_ID = gic.STRUCTURE_ID
and mic.CATEGORY_ID = gic.CATEGORY_ID
and m.ITEM_ID = gic.ITEM_ID
and upper(gic.CATEGORY_SET_NAME) = 'KLASA KG POZYCJI’
union all
select msi.segment1, ”opm_kg, t.CATEGORY_CONCAT_SEGS odm_kg
from apps.mtl_item_categories_v t, mtl_system_items_b msi
where msi.inventory_item_id = t.INVENTORY_ITEM_ID
and msi.organization_id = t.ORGANIZATION_ID
and msi.organization_id = 115
and t.CATEGORY_SET_NAME=’Klasa KG pozycji’
) v
where nvl(v.opm_kg,’BRAK’)|| (nvl(v.odm_kg,’BRAK’))<>'BRAKBRAK'
group by v.item_no