Hello! Welcome to the next lesson in our "SQL for Data Interrogation" module.
In our previous lessons, you've become proficient at analyzing data within a single table. You can select specific columns, filter rows with WHERE, summarize data with GROUP BY, and filter those summaries with HAVING. This is a powerful skill set, but real-world business data is rarely stored in one giant file.
For efficiency and organization, data is distributed across multiple, related tables. For example, you might have one table for customers, another for orders, and a third for products. The central challenge for any analyst is how to bring this scattered information together to answer meaningful questions, like "Which customers in New York bought which products last month?"
This lesson introduces the solution: SQL JOINS. We will focus on the most common and fundamental type: INNER JOIN. By the end of this lesson, you'll be able to write queries that combine data from multiple tables, unlocking a much deeper level of analysis and moving you closer to solving the complex data challenges you'll face as a Business Analyst.
Why Do We Need to Join Tables?
Before we dive into the syntax, it's crucial to understand why we need joins in the first place. The practice of splitting data into separate, specialized tables is called normalization. It's a core database design principle that avoids data duplication and ensures data integrity. For a Business Analyst, understanding this concept is important because it explains the structure of the data you'll be working with.
To get a clear, non-technical explanation of this concept, let's start with a short video.
Business Analyst Training For Beginners SQL Joins
The video 'Business Analyst Training For Beginners SQL Joins' by Business Analyst Guru explains why having one giant table is inefficient and how splitting data into multiple tables creates the need for joins. It also introduces the idea of primary and foreign keys, which are the 'links' we use to connect our tables.
Please watch from the beginning to 05:55. Focus on: The business reason for splitting data into multiple tables (e.g., employee details, designation details). The role of a common ID (like designation_ID) in linking these tables.
As the video explains, tables are connected by common columns. Typically, this involves a Primary Key (a unique identifier for a row in one table, like country_id in a countries table) and a Foreign Key (the same identifier used in another table to refer back to the first one, like country_id in a states table). The JOIN clause uses this key relationship to match and combine rows.
How INNER JOIN Works
There are several types of joins, but they all serve to combine tables. The INNER JOIN is the most frequently used. It returns only the rows where the key exists in both tables.

Let's visualize how the database performs this matching process.
SQL Joins Explained |¦| Joins in SQL |¦| SQL Tutorial
The video 'SQL Joins Explained' by Socratica provides a fantastic visual demonstration of how an INNER JOIN works. It shows, row by row, how records from two tables are matched based on a common ID.
Watch the segment from 01:31 to 02:54. Pay close attention to how a row from the 'Martian' table is matched with a row from the 'Base' table using the base_id.
Writing Your First INNER JOIN
Now that you understand the concept, let's look at the syntax. An INNER JOIN query has four main parts:
SELECT: The columns you want to display.FROM: The first (or "left") table.INNER JOIN: The second (or "right") table you want to connect.ON: The condition that tells SQL how to match the rows, usually by equating the primary and foreign keys.
SELECT
table1.column_name,
table2.column_name
FROM
table1
INNER JOIN
table2 ON table1.common_id = table2.common_id;
Notice that we specify the table for each column (table1.column_name). This is crucial to avoid ambiguity if columns in both tables have the same name (like id or name).
Let's watch a step-by-step guide to writing this query.
SQL Joins Explained |¦| Joins in SQL |¦| SQL Tutorial
Continuing with the Socratica video, this next segment walks through writing an INNER JOIN query from scratch. It also introduces a critical best practice: using table aliases.
Watch from 03:11 to 04:07 and then from 08:15 to 09:27. This will cover: The basic INNER JOIN syntax. Why specifying table names for columns is important (martian.base_id vs. base.base_id). How to use table aliases (FROM martian AS m) to make your queries shorter and more readable.
Using aliases (AS) is standard professional practice. It dramatically improves query readability, especially when joining multiple tables. From now on, you should always use aliases in your joins.
Here is the previous query rewritten with aliases:
SELECT
t1.column_name,
t2.column_name
FROM
table1 AS t1
INNER JOIN
table2 AS t2 ON t1.common_id = t2.common_id;
Test your understanding!
You have two tables: employees and departments.
employees table:
employee_id |
employee_name |
department_id |
|---|---|---|
| 1 | Alice | 101 |
| 2 | Bob | 102 |
| 3 | Charlie | 101 |
departments table:
dept_id |
dept_name |
|---|---|
| 101 | 'Marketing' |
| 102 | 'Sales' |
| 103 | 'Engineering' |
Write a query to produce a result that shows each employee's name and their department's name. Use table aliases (e for employees, d for departments).
Show answer
Here is the correct query:
SELECT
e.employee_name,
d.dept_name
FROM
employees AS e
INNER JOIN
departments AS d ON e.department_id = d.dept_id;
Result:
employee_name |
dept_name |
|---|---|
| 'Alice' | 'Marketing' |
| 'Bob' | 'Sales' |
| 'Charlie' | 'Marketing' |
Note that the 'Engineering' department does not appear in the result, because no employee is assigned to it. This is the core behavior of INNER JOIN.
Practical Application: Analyzing Ad Campaign Performance
Let's apply this to a scenario that reflects both your background in AdTech and the kind of tasks you'll perform in a BA interview. A common request is to measure advertising effectiveness by calculating metrics like Click-Through Rate (CTR). This almost always requires joining data from multiple tables.
The following resource presents a typical problem from a company like The Trade Desk.
The Trade Desk SQL Interview Questions
This article from DataLemur presents several SQL interview questions. We will focus on the one that directly relates to your experience: evaluating ad campaign performance.
Read the problem described in 'SQL Question 2: Ad Campaign Performance Evaluation'. Pay attention to: The business goal: calculating CTR by campaign, advertiser, and region. The data structure: information is split across three tables related by ad_id. The provided solution: study the SQL query and notice how it uses INNER JOIN (though they just use JOIN, which is shorthand for INNER JOIN) and aliases to bring the tables together before performing the GROUP BY and aggregation.
This example is an excellent showcase of a real-world BA task. You start with a business question, identify the necessary data points, figure out how the tables connect, and then write a query to produce the result. The query joins three tables to link campaigns to regions and impression events, then uses the GROUP BY and AVG() skills you already have to calculate the final metric.
This combination of JOIN with aggregations is one of the most powerful patterns in SQL for business analysis.
Conclusion
Congratulations on taking a huge step forward in your SQL journey! You've moved beyond single-table analysis and can now connect and query related datasets. This is a fundamental skill for any data-facing role, especially a Business Analyst.
Key Takeaways:
- Data is often split into multiple tables (normalization) to maintain organization and integrity.
INNER JOINis used to combine rows from two or more tables based on a matching key in both tables.- The query structure is
... FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.key = t2.key. - Using table aliases (
AS) is a professional best practice that makes queries cleaner and easier to read. - Combining
JOINwithGROUP BYand aggregate functions allows you to answer complex business questions that span multiple datasets.
Preview of the Next Lesson:INNER JOIN is perfect for finding matching data. But what if you want to find mismatches? For example, "Show me all customers, and if they have placed an order, show the order details." An INNER JOIN would exclude customers who haven't ordered. To handle this, we need an outer join. In the next lesson, we will explore the LEFT JOIN, which allows you to keep all records from the "left" table, regardless of whether they have a match in the right table.