PostgreSQL RIGHT JOIN or RIGHT OUTER JOIN
How PostgreSQL Right Join or Right Outer Join works?
The PostgreSQL RIGHT JOIN joins two tables and fetches rows based on a condition, which is matching in both the tables and the unmatched rows will also be available from the table written after the JOIN clause.
So, in case of RIGHT JOIN or RIGHT OUTER JOIN, PostgreSQL -
1. takes all selected values from the right table
2. combines them with the column names ( specified in the condition ) from the left table
3. retrieve the matching rows from both the associated tables.
4. sets the value of every column from the left table to NULL which is unmatched with the right table.
Select * FROM table1 RIGHT [ OUTER ] JOIN table2 ON table1.column_name=table2.column_name;
Pictorial Presentation of PostgreSQL Right Join or Right Outer Join
PostgreSQL RIGHT join fetches a complete set of records from the right, with the matching records (depending on the availability) in left. The result is NULL in the left side when no matching will take place.
Sample table: Customer
Sample table: Item
Sample table: Invoice
RIGHT JOIN item
RIGHT OUTER JOIN item
In the above example, the item_no I8 of item table not exists in the invoice table, and for this row in the item table, a new row have been generated in the invoice table and sets the value NULL for this row.
Pictorial Presentation for the above example
- Weekly Trends
- 100 Python Projects for Beginners with solution
- Mastering NumPy: 100 Exercises with solutions
- SQL Tutorial
- SQL Inner Join
- Python Exercises, Practice, Solution
- Python Interview Questions and Answers: Comprehensive Guide
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises