There is no simple answer, because it depends on many factors.
Please, see:
Oracle: Complex recordsets[
^] and
Creating and Using Temporary Tables in Oracle[
^]
In your case i'd suggest to use simple
SELECT
statement together with suitable
JOINs[
^] AND
COALESCE[
^] function.
COALESCE
function is used to replace nulls with default values.
Finally, your query might look like:
SELECT HT.<Field_List>, COALESCE(AL.ShipFrom, AH.ShipFrom) AS ShipFrom, COALESCE(AL.ShipTo, AH.ShipTo) AS ShipTo
FROM HeaderTable AS HT LEFT JOIN AddressLineTable AS AL ON HT.invoice_line_id = AL.invoice_line_id
LEFT JOIN AdressHeaderTable AS AH ON HT.invoice_line_id = HT.invoice_line_id
As you can see, in case when
AL.ShipFrom
will be
NULL
, it should be replaced with
AH.ShipFrom
.
Note: i have no idea about your data structure, so the query have to be changed to your needs.
More useful information about JOINs, you'll find here:
Visual Representation of SQL Joins[
^]