📅  最后修改于: 2023-12-03 15:03:23.561000             🧑  作者: Mango
In Oracle, INNER JOIN is a type of join that combines rows from two or more tables based on a related column between them. It returns only the matched rows that satisfy the join condition.
The syntax for an INNER JOIN in Oracle is as follows:
SELECT column1, column2, ...
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;
In this syntax:
table1
and table2
are the tables you want to join.column_name
is the column that is common between the tables used to join them.column1, column2, ...
are the columns you want to select from the result.Consider two tables, employees
and departments
, with a common column department_id
.
| employee_id | employee_name | department_id | |-------------|---------------|---------------| | 1 | John Doe | 1 | | 2 | Jane Smith | 2 | | 3 | Alice Johnson | 1 |
| department_id | department_name | |---------------|-----------------| | 1 | Sales | | 2 | Marketing | | 3 | Finance |
To join these two tables using INNER JOIN and retrieve employee names along with their department names:
SELECT e.employee_name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;
The result would be:
| employee_name | department_name | |----------------|-----------------| | John Doe | Sales | | Jane Smith | Marketing | | Alice Johnson | Sales |
INNER JOIN is a useful feature in Oracle that allows you to combine rows from multiple tables based on a common column. It helps in retrieving related data efficiently and obtaining meaningful results.