The Left Outer Join
Read the first article in this series here.
The visual reprsentation of the Left Outer Join is as shown in picture 1. In picture 1 a represents CUSTOMERS table and b represents TRANSACTION table.
A simple query would be like this
SELECT customers.customer_no, customers.customer_Name, transaction.Time_Stamp
FROM customers
LEFT OUTER JOIN transaction
on customers.Customer.no = transaction.Customer.no
The table designs are revisited .
CUSTOMERS Table
Customer_no |
Cust_Name |
Mid_Name |
Last_Name |
Street Name |
City |
Pincode |
|
TRANSACTION Table
Transaction_no |
Customer_no |
Amount_no |
Amount |
desc |
Time_stamp |
Balance |
Let us take a look at the records of both the tables .
CUSTOMERS Table :
|
Customer _no |
Cust_ Name |
|
|
|
|
C101 |
PERRY |
|
|
|
|
C102 |
BEIBER |
|
|
|
|
C103 |
SWIFT |
|
|
|
|
C104 |
BYONCE |
|
|
|
|
C105 |
LADY |
|
|
|
|
TRANSACTION |
Table: |
|
|
|
|
|
|
|
||
|
Transaction_no |
Customer_ no Time_stamp |
|
||
|
T125437 |
C102 |
01/01/2015 |
|
|
|
T678975 |
C103 |
09/01/2015 |
|
|
|
T999567 |
C105 |
12/09/2015 |
|
|
|
The ouput of the left outer join would be |
|
|||
|
|
|
|
|
|
|
Customer _no |
Cust_ Name |
Time_stamp |
|
|
|
C101 |
PERRY |
xxx |
|
|
|
C102 |
BEIBER |
01/01/2015 |
|
|
|
C103 |
SWIFT |
09/01/2015 |
|
|
|
C104 |
BYONCE |
xxx |
|
|
|
C105 |
LADY |
12/09/2015 |
|
This implies ,the result set of a query that uses left outer join will have all records from table a and those that intersect table a from table b or those that have a matching value in table a for the field on which the left outer join is made ;in this case the customer _no field.
The picture 2 above is the representation of how the result set is arrived at for the query ,using Left Outer Join, in discussion.