1. Inner Join: An inner join is used to combine rows from two or more tables based on a common field between them. For example, the following query returns all rows from the orders table where the customer_id is present in the customers table:

SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id

2. Left Join: A left join is used to return all rows from the left table, even if there are no matches in the right table. For example, the following query returns all rows from the orders table, even if there are no matching rows in the customers table:

SELECT * FROM orders LEFT JOIN customers ON orders.customer_id = customers.customer_id

3. Right Join: A right join is used to return all rows from the right table, even if there are no matches in the left table. For example, the following query returns all rows from the customers table, even if there are no matching rows in the orders table:

SELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.customer_id

4. Full Join: A full join is used to combine rows from two or more tables, even if there are no matches in either table. For example, the following query returns all rows from both the orders and customers tables, even if there are no matching rows in either table:

SELECT * FROM orders FULL JOIN customers ON orders.customer_id = customers.customer_id

Leave a Reply

Your email address will not be published. Required fields are marked *