Course contentsShow
← Databases & SQL
Lesson 199 of 1,9533. Relational Algebra in PracticeFree lesson

Left versus Right Join Symmetry

Analyze the impact of directional focus on query readability and execution plan.

In this lesson, you will learn why LEFT JOIN and RIGHT JOIN are mathematically identical and how choosing between them impacts the readability and performance of your queries.

The Symmetry of Direction

If you have two sets of data—let's call them Customers and Orders—a join operation is essentially a way to describe their relationship. Mathematically, a LEFT JOIN and a RIGHT JOIN are symmetric. If you write:

SELECT * FROM Customers LEFT JOIN Orders ON Customers.id = Orders.customer_id;

You are defining the Customers table as the "preservation" side; even if a customer has no orders, they will still appear in your results with NULL values for the order columns. If you were to swap the table order and use a RIGHT JOIN, you produce the exact same set:

SELECT * FROM Orders RIGHT JOIN Customers ON Customers.id = Orders.customer_id;

Both queries result in the same set of tuples. The relationship is commutative in intent, even if the syntax forces a directional choice.

Readability and Execution Plans

While they are logically symmetric, they are not always treated equally in practice.

Readability: Most database professionals prefer LEFT JOIN exclusively. It allows the reader to follow the "primary" table from left to right, matching how we read English text. Using RIGHT JOIN often forces a developer to mentally flip the query logic, which can lead to mistakes in complex queries involving multiple joins.

Execution Plans: From a performance perspective, the database engine’s query optimizer is smart enough to see that a RIGHT JOIN is just a LEFT JOIN in disguise. When the optimizer generates the execution plan, it often converts a RIGHT JOIN into a LEFT JOIN internally to align with its preferred processing order. Because the engine "normalizes" this during planning, you rarely see a difference in execution time. However, keeping your code consistent (by favoring LEFT JOIN) makes your queries easier for both the engine to cache and for humans to debug.

Key Takeaway: Because LEFT JOIN and RIGHT JOIN are mathematically symmetric, favor the LEFT JOIN syntax to improve code readability and maintainability without sacrificing performance.