SQL left Outer Join: Understand the left join and then understand the right join
Two-Table Outer Join
Shipping table
Customer ID, customer name, product ID, product quantity, remarks
Create Table a_prod_out
(
Custom_id int not null,
Custom_name varchar (200) not null,
Prod_id int default 0 null,
Prod_num int default 0 null,
Remark varchar (500) null,
Constraint pk_a_prod_out primary key (custom_id)
)
Product table
Product ID, product name, manufacturer
Create Table B _prod
(
Prod_id int not null,
Prod_name varchar (200) not null,
Manufacturer_id int default 0 null,
Remark varchar (500) null,
Constraint pk_ B _prod primary key (prod_id)
)
Left join
The left join is based on the left table, and some data on the right is connected, and the condition is the product ID.
The information in the left table is displayed, indicating that the join conditions are met on the right of the connection.
Select a. custom_id, A. custom_name, B. prod_name, B. manufacturer_id
From a_prod_out a left Outer Join B _prod B
On a. prod_id = B. prod_id;
Three-Table Outer Join
What products do the customer apply?
Create Table a_mfter
(
Manufacturer_id int not null,
Manufacturer_name varchar (200) not null,
Constraint pk_a_mfter primary key (manufacturer_id)
)
Select a. custom_id, A. custom_name, B. prod_name, C. manufacturer_name
From a_prod_out
Left Outer Join B _prod B
On a. prod_id = B. prod_id
Left Outer Join a_mfter C
On B. manufacturer_id = C. manufacturer_id;
The SQL results are also based on the shipping table in the left table, and are connected to the product table and vendor table.