Table Left Join TSQL Tutorial

Left Join Example:

Customers Table

CUSTOMER_IDCUSTOMER_NAMECONTACT_NAME
1CUSTOMER_1NAME_1
2CUSTOMER_2NAME_2
3CUSTOMER_3NAME_3
4CUSTOMER_4NAME_4
5CUSTOMER_5
6CUSTOMER_6

Contracts Table

CONTRACT_IDCUSTOMER_IDAMOUNT
11400
22500
33700
411000
521200
64900
732000
821500

SELECT c.customer_id, c.customer_name, ctr.contract_id, ctr.amount
 FROM customers c LEFT JOIN contracts ctr
    ON c.customer_id = ctr.customer_id
ORDER BY c.customer_id ;

Result:

Customer_IdCustomer_NameContract_IdAmount
1CUSTOMER_11400
1CUSTOMER_141000
2CUSTOMER_22500
2CUSTOMER_251200
2CUSTOMER_281500
3CUSTOMER_33700
3CUSTOMER_372000
4CUSTOMER_46900
5CUSTOMER_5
6CUSTOMER_6