oracle
  1. oracle-inner-join

Inner Join - ( Oracle Joins )

An inner join is an Oracle join that returns only the rows that have matching values in both tables being joined. It is also known as a simple join.

Syntax

The syntax for performing an inner join in Oracle is as follows:

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

Here, SELECT is used to select the columns from the tables, table1 and table2 are the tables to be joined, and column1 and column2 are the columns to be selected from each table. The ON clause is used to specify the join condition.

Example

Consider the following two tables, customers and orders:

customers table

ID  NAME        AGE     CITY
-----------------------------
1   John Smith  35      New York
2   Sarah Lee   28      Chicago
3   Mark Brown  42      Los Angeles


orders table

ID  CUSTOMER_ID     PRODUCT
---------------------------
1   1               Book
2   1               Chair
3   2               Desk
4   3               Lamp

Here is an example of an inner join that joins the customers and orders tables on the ID column:

SELECT c.NAME, o.PRODUCT
FROM customers c
INNER JOIN orders o
ON c.ID = o.CUSTOMER_ID;

Output

The output of the inner join query on the customers and orders tables would be:

NAME          PRODUCT
---------------------
John Smith    Book
John Smith    Chair
Sarah Lee     Desk
Mark Brown    Lamp

Explanation

In the above example, we have performed an inner join on the customers and orders tables using the ID and CUSTOMER_ID columns, respectively. The resulting table contains only the rows where the ID and CUSTOMER_ID values match. We have selected the NAME column from the customers table and the PRODUCT column from the orders table.

Use

Inner joins are commonly used in Oracle SQL to combine data from two or more tables based on a common column. They can be used to retrieve data that is spread across multiple tables, making it easier to analyze and manipulate data.

Important Points

  • An inner join is an Oracle join that returns only the rows that have matching values in both tables being joined.
  • The ON clause is used to specify the join condition.
  • Inner joins are commonly used to combine data from two or more tables based on a common column.

Summary

In summary, an inner join is an Oracle join that returns only the rows that have matching values in both tables being joined. It is commonly used to combine data from multiple tables and can help to make it easier to analyze and manipulate large datasets.

Published on: