Left Join that always includes null records Left Join that always includes null records oracle oracle

Left Join that always includes null records


You don't need a join here at all:

SELECT  customer_id, NULL AS location_id, addressFROM    customersUNION ALLSELECT  customer_id, location_id, addressFROM    locations


You can try a full outer join. For example:

SELECT    CUSTOMERS.CUSTOMER_ID,   LOCATIONS.LOCATION_ID,   NVL(LOCATIONS.ADDRESS,CUSTOMERS.ADDRESS) ADDRESS             FROM  CUSTOMERS     FULL OUTER JOIN  LOCATIONS ON (CUSTOMERS.CUSTOMER_ID=LOCATIONS.CUSTOMER_ID)


If you want to join the two tables even when there is a non match, you will need to use IS NULL on your joined columns.

For example.

Table 1:CustomerIDCustomerName

.

Table 2:CustomerIDCustomerEmail

.

Select,CustomerID,CustomerName,ISNULL (CustomerEmail, NULL) AS CustomerEmailFROM table1LEFT JOIN table2ON table1.CustomerID = table2.CustomerID

This wil bring back results with NULL