Types of SQL JOins
Types of SQL JOins
1. *INNER JOIN*: Returns records that have matching values in both tables.
2. *LEFT JOIN* (or *LEFT OUTER JOIN*): Returns all records from the left table, and the matched records
from the right table. If there's no match, the result will contain NULL values.
3. *RIGHT JOIN* (or *RIGHT OUTER JOIN*): Similar to LEFT JOIN, but returns all records from the right
table.
4. *FULL JOIN* (or *FULL OUTER JOIN*): Returns all records from both tables, with NULL values in the
columns where there's no match.
5. *CROSS JOIN*: Returns the Cartesian product of both tables, with each row of one table combined
with each row of the other table.
```
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;
```
1. *INNER JOIN*:
```
FROM orders
```
2. *LEFT JOIN*:
```
FROM orders
ON orders.customer_id = customers.customer_id;
```
3. *RIGHT JOIN*:
```
FROM orders
ON orders.customer_id = customers.customer_id;
```
4. *FULL JOIN*:
```
FROM orders
ON orders.customer_id = customers.customer_id;
```
5. *CROSS JOIN*:
```
FROM orders
```
2. Using the wrong type of join (e.g., using INNER JOIN instead of LEFT JOIN).
Best Practices