SQL join with examples for beginners
There are four types of JOINs, today I will briefly describe about these categories.
N.B: This is from my personal note, if you have any confusion please let me know.
The Four different types of JOINs
(INNER) JOIN: It will display the matching values in both tables. FULL (OUTER) JOIN: It will show all records that match either left or right table records. LEFT (OUTER) JOIN: Select records from the first (left-most) table with matching right table records. RIGHT (OUTER) JOIN: Select records from the second (right-most) table with matching left table records.
Example
Suppose we have three table Customer,Order and Supplier
Customer Order Suplier ----------------------- ----------------------------- ----------------------- id ---> (Primary key) order_id ---> (Primary key) id ---> (Primary key) custmer_name ooder_numbner company_namne city order_date city country customer_id--->(foreign key) country phone order_notes phone total_amount
comparing these three tables i will describe the four types of SQL join,
Here are some questions and it will solve using the four types of SQL joins
Problem 1: Display all the customers name,city their order and order notes in 10th may 2020.-->(Inner Join) Problem 2: List all customers and the total amount they spent irrespective whether they placed any orders or not.---> (Left Join) Problem 3: List customers that have not placed orders. --->(Right Join) Problem 4: Match all customers and suppliers by country.--->(Full Join)
for the above question SQL codes are written, with this information you can learn about SQL Join easily.
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.