Grokking SQL for Tech Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
INNER JOIN
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

An INNER JOIN in SQL is a method for combining rows from two or more tables based on a related column between them. The join condition is specified using the ON keyword, indicating which columns in each table should have matching values for the rows to be included in the result set.

Syntax

SELECT * FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;

Example

Let's consider two tables, employees and departments

Image

Now, let's perform an INNER JOIN to retrieve information about employees and their corresponding departments:

MYSQL
MYSQL

. . . .

Result

Image

In this example, the INNER JOIN is based on the equality of the department_id columns in both tables. The result set includes only the rows where there is a match between the department_id values in the employees and departments tables. As a result, we get a cohesive view of employees and their respective departments.

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible