| transaction_id | amount | customer_id |
|---|---|---|
| primary key | foreign key | |
| 1000 | 4.99 | 3 |
| 1001 | 2.86 | 2 |
| 1002 | 3.33 | 3 |
| 1003 | 2.15 | 1 |
| customer_id | name |
|---|---|
| primary key | |
| 1 | Hans |
| 2 | John |
| 3 | Laila |
| transaction_id | amount | customer_id | name |
|---|---|---|---|
| primary key | foreign key | ||
| 1000 | 4.99 | 3 | Laila |
| 1001 | 2.86 | 2 | John |
| 1002 | 3.33 | 3 | Laila |
| 1003 | 2.15 | 1 | Hans |
INSERT INTO transactions (amount, customer_id)
VALUES (1.00, NULL);
SELECT * FROM transactions;| transaction_id | amount | customer_id |
|---|---|---|
| primary key | foreign key | |
| 1000 | 4.99 | 3 |
| 1001 | 2.86 | 2 |
| 1002 | 3.33 | 3 |
| 1003 | 2.15 | 1 |
| 1004 | 1.00 | NULL |
INSERT INTO customers (name)
VALUES ("Julia");
SELECT * FROM customers;| customer_id | name |
|---|---|
| primary key | |
| 1 | Hans |
| 2 | John |
| 3 | Laila |
| 4 | Julia |
SELECT *
FROM transactions INNER JOIN customers
ON transactions.customer_id = customers.customer_id;
| transaction_id | amount | customer_id | name |
|---|---|---|---|
| 1000 | 4.99 | 3 | Laila |
| 1001 | 2.86 | 2 | John |
| 1002 | 3.33 | 3 | Laila |
| 1003 | 2.15 | 1 | Hans |
SELECT *
FROM transactions INNER JOIN customers
ON transactions.customer_id = customers.customer_id;| transaction_id | amount | name |
|---|---|---|
| 1000 | 4.99 | Laila |
| 1001 | 2.86 | John |
| 1002 | 3.33 | Laila |
| 1003 | 2.15 | Hans |
SELECT *
FROM transactions LEFT JOIN customers
ON transactions.customer_id = customers.customer_id;;| transaction_id | amount | customer_id | customer_id | name |
|---|---|---|---|---|
| 1000 | 4.99 | 3 | 3 | Laila |
| 1001 | 2.86 | 2 | 2 | John |
| 1002 | 3.33 | 3 | 3 | Laila |
| 1003 | 2.15 | 1 | 1 | Hans |
| 1004 | 1.00 | NULL | NULL | NULL |
SELECT *
FROM transactions RIGHT JOIN customers
ON transactions.customer_id = customers.customer_id;;| transaction_id | amount | customer_id | customer_id | name |
|---|---|---|---|---|
| 1003 | 2.15 | 1 | 1 | Hans |
| 1001 | 2.86 | 2 | 2 | John |
| 1000 | 4.99 | 3 | 3 | Laila |
| 1002 | 3.33 | 3 | 3 | Laila |
| NULL | NULL | NULL | 4 | Julia |