/

/

How to use the SQL Join

HOW TO

How to use the SQL Join

How to use the SQL Join

How to use the SQL Join

May 1, 2024

May 1, 2024

May 1, 2024

In this section, we will go through the different types of joins. A join is used to combine data from two or more tables into one table and find records where there are matching values between them.

Inner Join - Used to combine records where there is a match in both tables.

Left Outer Join - Used to combine records from the left table that do not have matches in the right table, or vice versa. This can be useful when you want all rows from one table with no duplicates (for example, if you want all users with their emails). The left outer join returns all rows from a table's left side and only those from another table that match its right side. A left outer join could be used to find all customers who have not made a purchase, even if they already have an account number.

Right Outer Join - Used to combine rows on the right side of your query with duplicate values in order to make multiple copies of each unique value (for example, if you want all users along with their emails). This can be useful when you want all users along with their emails; however, it's best practice not use this type of join unless absolutely necessary because it may lead to confusing results due to duplicated data being displayed multiple times onscreen at once! A right outer join returns all rows from a table's right side and only those from another table that match its left side. A right outer join could be used to find products with no inventory levels or prices.

A full outer join returns all rows for both tables being joined regardless of whether or not there are any matching values between them; this includes nulls as well (unlike an inner equi-join).


SELECT city.name, country.name FROM city

INNER JOIN country on city.country_id=country.country_id

SELECT city.name, country.name FROM city

LEFT JOIN country on city.country_id=country.country_id

SELECT city.name, country.name FROM city

RIGHT JOIN country on city.country_id=country.country_id

Share this

More Articles

More Articles

More Articles