select
itoh.header_number Transfer_Order,
itol.SHIPPED_QTY ,
itol.REQUESTED_QTY,
itol.RECEIVED_QTY,
itol.DELIVERED_QTY,
itol.SOURCE_SUBINVENTORY_CODE Transfer_subiinventory
(select DISTINCT (esi.ITEM_NUMBER and esi.item_type)
from egp_system_items_b esi
where INVENTORY_ITEM_ID = itol.INVENTORY_ITEM_ID)
From
inv_transfer_order_headers itoh, inv_transfer_order_lines itol
where
itoh.HEADER_ID = itol.HEADER_ID
2 Answers
It is always helpful to provide some sort of DDL and sample data so that the problem can be demo'ed. It's also useful to provide your full version number, some features are only available in recent versions, I will assume you are using at least version 12.2 (as that is the current latest supported version)
This is only necessary if you do not want to distinct against all of the columns in your result set. You can use a lateral join to join to a correlated subquery:
select
itoh.header_number Transfer_Order,
itol.SHIPPED_QTY ,
itol.REQUESTED_QTY,
itol.RECEIVED_QTY,
itol.DELIVERED_QTY,
itol.SOURCE_SUBINVENTORY_CODE Transfer_subiinventory,
esi_subq.ITEM_NUMBER,
esi_subq.item_type
From
inv_transfer_order_headers itoh, inv_transfer_order_lines itol
, lateral
(select DISTINCT esi.ITEM_NUMBER , esi.item_type
from egp_system_items_b esi
where INVENTORY_ITEM_ID = itol.INVENTORY_ITEM_ID
) esi_subq
where
itoh.HEADER_ID = itol.HEADER_ID
I've made a small dbfiddle to demo
You are also free to use the newer join syntax but you'll need to use different keywords.
select
itoh.header_number Transfer_Order,
itol.SHIPPED_QTY ,
itol.REQUESTED_QTY,
itol.RECEIVED_QTY,
itol.DELIVERED_QTY,
itol.SOURCE_SUBINVENTORY_CODE Transfer_subiinventory,
esi_subq.ITEM_NUMBER,
esi_subq.item_type
From
inv_transfer_order_headers itoh
join inv_transfer_order_lines itol
on itoh.HEADER_ID = itol.HEADER_ID
outer apply
(select DISTINCT esi.ITEM_NUMBER , esi.item_type
from egp_system_items_b esi
where INVENTORY_ITEM_ID = itol.INVENTORY_ITEM_ID
) esi_subq
select DISTINCT ( esi.ITEM_NUMBER and esi.item_type)to do? A subquery in theselectlist can only return a single value (since it only produces a single column in the result set). Perhaps you want to do a string concatenation of the two columns (select distinct esi.item_number || esi.item_type)? But that's a wild guess without a more detailed description of the problem.JOINsyntax in the ANSI-92 SQL Standard (almost 30 years ago) and its use is discouraged