Inner Join

SQL INNER JOIN is a type of JOIN operation used to combine rows from two or more tables based on a matching condition between the tables. It is one of the most commonly used JOIN types in SQL, along with LEFT JOIN and RIGHT JOIN.

Syntax

The syntax for an INNER JOIN is as follows:

SELECT column1, column2, ...
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

In this syntax, column1, column2, and so on are the columns that you want to select from the tables. table1 and table2 are the names of the tables that you want to join. The ON clause specifies the condition on which the tables are joined, using the syntax table1.column_name = table2.column_name. This condition specifies that the values in the specified columns of the two tables must match in order for the rows to be combined in the result set.

Example

For example, consider two tables: employees and departments. The employees table contains columns such as employee_id, first_name, last_name, and department_id, while the departments table contains columns such as department_id and department_name.

To join these two tables based on the department_id column, you can use the following SQL statement:

SELECT 
employees.employee_id, employees.first_name, 
employees.last_name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.department_id;

This SQL statement selects the employee_id, first_name, and last_name columns from the employees table, and the department_name column from the departments table. It then joins the two tables on the department_id column and returns the result set.

In summary, SQL INNER JOIN is a powerful feature that allows you to combine rows from two or more tables based on a matching condition. It is an essential tool for querying and analyzing data from multiple tables in a database.