Table joins
Table joins are used to combine data from more than one table based on certain conditions on a certain column or columns.
For example, let's assume the following two tables exist:
CREATE TABLE customers ( id UUID PRIMARY KEY, name STRING NOT NULL ); CREATE TABLE purchase_orders ( id UUID PRIMARY KEY, customer_id UUID, n_of_items INT, total_price DECIMAL(10,2) );
Now, let's look at each of the JOIN
types with an example, as follows:
INNER JOIN
: Returns rows from the left and right operands that match the condition.
Let's look at the following example involving an inner join between the customers
and purchase_orders
tables:
SELECT a.id as customer_id, a.name AS customer_name, b.id AS purchase_order_id FROM customers AS...