Types of Joins
Learn how to combine rows from two or more tables.
Learn how to combine rows from two or more tables. This hands-on tutorial focuses on practical implementation of types of joins concepts.
What is a JOIN?
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
(Note: Our playground has limited sample data, but we can demonstrate the concepts.)
Let's assume we have an Orders table linked to Customers.
(We will create a temporary Orders table for this example in the background).
Inner Join
Returns records that have matching values in both tables.
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
Left Join
Returns all records from the left table (Customers), and the matched records from the right table (Orders).
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
Right Join
Returns all records from the right table, and the matched records from the left table. (Note: SQLite/SQL.js supports LEFT JOIN but does not fully support RIGHT JOIN syntax directly in all versions, usually you swap the tables and use LEFT JOIN).
Interactive Example
Let's try a simulated join. We'll join Products with a hypothetical Categories table (created on the fly for demonstration if possible, otherwise we can simulate with existing data). Since we only have Customers and Products in the default schema, let's look at Customers.
For this playground, let's perform a cross-product to see matching logic (or just select from multiple tables).