> ## Content Index
> Fetch the complete content index at: https://ksnk.media/llms.txt
> Use this file to discover other available public pages before exploring further.

# Explore how SQL JOINs work
- URL: https://ksnk.media/explore-how-sql-joins-work/
- Published: 2024-05-16T08:24:10.000Z
- Updated: 2026-04-03T10:00:37.000Z
- Description: Master SQL JOINs with our guide! Learn how to connect tables effectively and enhance your database skills for better data management.
- Author: Aleksandr Kosenko
- Tags: Blog

## Common **JOIN**s

- **INNER JOIN:** a function that returns records with matching values in both tables
- **LEFT JOIN:** a function that returns all the records from the left table (first mentioned) and only the matching records from the right table (second mentioned)
- **RIGHT JOIN:** a function that returns all records from the right table (second mentioned) and only the matching records from the left table (first mentioned).
- **OUTER JOIN:** a function that combines the **RIGHT JOIN** and **LEFT JOIN** to return all matching records in both tables.

## Example 1: **INNER JOIN**

```sql
SELECT
	employees.name AS employee_name,
	employees.role AS employee_role,
	departments.name AS department_name
FROM
	employee_data.employees AS employees
INNER JOIN
	employee_data.departments AS departments
	ON employees.department_id = departments.department_id

```

## Example 2: **LEFT JOIN**

```sql
SELECT
	employees.name AS employee_name,
	employees.role AS employee_role,
	departments.name AS department_name
FROM
	employee_data.employees AS employees 
LEFT JOIN
	employee_data.departments AS departments
    ON employees.department_id = departments.department_id

```

## Example 3: **RIGHT JOIN**

```sql
SELECT
	employees.name AS employee_name,
	employees.role AS employee_role,
	departments.name AS department_name
FROM
	[your-project-id].employee_data.employees AS employees 
RIGHT JOIN
	[your-project-id].employee_data.departments AS departments
    ON employees.department_id = departments.department_id

```

## Example 4: **FULL OUTER JOIN**

Now, you’ll create a new query that uses **FULL OUTER JOIN**.

1. Using the query window tabs to navigate between queries, copy and paste the query from Example 3 into the new query window.
2. In line 7, replace **RIGHT JOIN** with **FULL OUTER JOIN**.
3. Run the query by selecting the **Run** button.

If you prefer, you can copy and paste the following query into the query window in BigQuery.

```sql
SELECT
	employees.name AS employee_name,
	employees.role AS employee_role,
	departments.name AS department_name
FROM
	[your-project-id].employee_data.employees AS employees 
OUTER JOIN
	[your-project-id].employee_data.departments AS departments
      ON employees.department_id = departments.department_id

```

## Type of JOINs

![](https://ksnk.media/content/images/2026/04/migrate_Captura-de-pantalla-2024-05-16-a-las-10.26.58-1.png)

img by Google

## For more information

**JOIN**s are going to be useful for working with relational databases and SQL—and you will have plenty of opportunities to practice them on your own. Here are a few other resources that can give you more information about **JOIN**s and how to use them:

- [**SQL JOINs**](https://www.w3schools.com/sql/sql%5Fjoin.asp?ref=ksnk.media)**:** This is a good basic explanation of **JOIN**s with examples. If you need a quick reminder of what the different **JOIN**s do, this is a great resource to bookmark and come back to later.
- [**Database JOINs - Introduction to JOIN Types and Concepts**](https://www.essentialsql.com/introduction-database-joins/?ref=ksnk.media)**:** This is a really thorough introduction to **JOIN**s. Not only does this article explain what **JOIN**s are and how to use them, but it also explains the various scenarios in more detail of when and why you would use the different **JOIN**s. This is a great resource if you are interested in learning more about the logic behind **JOIN**ing.
- [**SQL JOIN Types Explained in Visuals**](https://dataschool.com/how-to-teach-people-sql/sql-join-types-explained-visually/?ref=ksnk.media)**:** This resource has a visual representation of the different **JOIN**s. This is a really useful way to think about **JOIN**s if you are a visual learner, and it can be a really useful way to remember the different **JOIN**s.
- [**SQL JOINs: Bringing Data Together One Join at a Time**](https://towardsdatascience.com/sql-join-8212e3eb9fde?ref=ksnk.media)**:** Not only does this resource have a detailed explanation of **JOIN**s with examples, but it also provides example data that you can use to follow along with their step-by-step guide. This is a useful way to practice **JOIN**s with some real data.
- [**SQL JOIN:**](https://www.dofactory.com/sql/join?ref=ksnk.media) This is another resource that provides a clear explanation of **JOINs** and uses examples to demonstrate how they work. The examples also combine **JOIN**s with aliasing. This is a great opportunity to see how **JOIN**s can be combined with other SQL concepts that you have been learning about in this course.

## Key takeaways

- JOIN is a SQL clause used to combine rows from two or more tables based on a related column.
- There are four common JOINs used by data analysts: inner, left, right, and outer.
- An inner JOIN returns records with matching values in both tables.
- A left JOIN returns all records from the left table and the matching records from the right table.
- A right JOIN does the opposite, returning all records from the right table and the matching records from the left table.
- An outer JOIN combines right and left JOINs to return all matching records in both tables.
- JOINs can make working with multiple data sources easier and can clarify relationships between tables.

## P.S.

## Basic syntax for aliasing

**Aliasing** is the process of using aliases. In SQL queries, aliases are implemented by making use of the **AS** command. The basic syntax for the **AS** command can be seen in the following query for aliasing a table:

```sql
SELECT column_name(s)
FROM table_name AS alias_name;

```

## For more information

If you are interested in learning more about aliasing, here are some resources to help you get started:

- [**SQL Aliases**](https://www.w3schools.com/sql/sql%5Falias.asp?ref=ksnk.media)**:** This tutorial on aliasing is a really useful resource to have when you start practicing writing queries and aliasing tables on your own. It also demonstrates how aliasing works with real tables.
- [**SQL Alias**](https://www.sqltutorial.org/sql-alias/?ref=ksnk.media)**:** This detailed introduction to aliasing includes multiple examples. This is another great resource to reference if you need more examples.
- [**Using Column Aliasing**](https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4%5F3.5&docsetId=sqlproc&docsetTarget=p0aymxwsvbt5wcn1lncugwjtf758.htm&locale=en&ref=ksnk.media)**:** This is a guide that focuses on column aliasing specifically. Generally, you will be aliasing entire tables, but if you find yourself needing to alias just a column, this is a great resource to have bookmarked.