- SAP ABAP
- What is SAP ABAP
- SAP ABAP Data Dictionary and Domain
- SAP ABAP Data Element
- SAP ABAP Database Table
- SAP ABAP Database tables and views
- SAP ABAP Foreign Key
- SAP ABAP Indexes
- SAP ABAP Structure
- SAP ABAP Package
- SAP ABAP Adding Fields to SAP Standard Table
- SAP ABAP Internal Table and Database Table
- SAP ABAP Select Option and Parameter
- SAP ABAP Types of Internal Table
- SAP ABAP ways of Declaring Internal Tables
- SAP ABAP Mastering Initialization Technique
- SAP ABAP Operations on Internal Table
- SAP ABAP Record Retrieval
- SAP ABAP Insert, Modify and Delete data in the Internal table by using Keywords
- SAP ABAP Sorting and Removing Adjacent Duplicates
- SAP ABAP Seamless Data Transfer Between Internal Tables
- SAP ABAP Search Help Types
- SAP ABAP Lock Objects and Types
- SAP ABAP Buffering and Its Types
- SAP ABAP TMG
- SAP ABAP Table Types
- SAP ABAP Views
- SAP ABAP Control Break Statement
- SAP ABAP COMMIT and ROLLBACK
- SAP ABAP Joins
- SAP For All Entries
- SAP ABAP Procedure to Fill Final Internal Table
- SAP ABAP Modularization
- SAP ABAP Function Group and Function Module
- SAP ABAP SELECT Options
24DDIC0608 – Understanding Joins and Their Types
What is a Join?
A join is a SQL operation that allows you to combine data from two or more tables based on a common field between them. This helps in retrieving related data from multiple tables in a single query.
Types of Joins
ABAP supports several types of joins, each serving a different purpose. The most common types are:
- Inner Join
- Left Outer Join
- Right Outer Join
- Cross Join
Inner Join
An Inner Join returns only the rows where there is a match in both tables. If there is no match, the row is not included in the result set.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
INNER JOIN table2 AS b
ON a~common_field = b~common_field.
In this example, the query retrieves rows from table1 and table2 where common_field matches in both tables.
Left Outer Join
A Left Outer Join returns all rows from the left table and the matched rows from the right table. If there is no match, the result is NULL from the right table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
LEFT OUTER JOIN table2 AS b
ON a~common_field = b~common_field.
This query retrieves all rows from table1, and the matching rows from table2. If there is no match, it shows NULL for columns from table2.
Right Outer Join
A Right Outer Join is similar to a Left Outer Join but retrieves all rows from the right table and the matched rows from the left table. If there is no match, the result is NULL from the left table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
RIGHT OUTER JOIN table2 AS b
ON a~common_field = b~common_field.
This query retrieves all rows from table2, and the matching rows from table1. If there is no match, it shows NULL for columns from table1.
Cross Join
A Cross Join returns the Cartesian product of the two tables, meaning it combines each row of the first table with each row of the second table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a,
table2 AS b.
This query retrieves all possible combinations of rows from table1 and table2.
When to Use Each Join Type
– Inner Join: Use when you only need rows with matching values in both tables.
– Left Outer Join: Use when you need all rows from the left table, regardless of whether there is a match in the right table.
– Right Outer Join: Use when you need all rows from the right table, regardless of whether there is a match in the left table.
– Cross Join: Use when you need all possible combinations of rows from both tables.
Author : Aniket Pawar, 9373518385
24DDIC0608 – Understanding Joins and Their Types
What is a Join?
A join is a SQL operation that allows you to combine data from two or more tables based on a common field between them. This helps in retrieving related data from multiple tables in a single query.
Types of Joins
ABAP supports several types of joins, each serving a different purpose. The most common types are:
- Inner Join
- Left Outer Join
- Right Outer Join
- Cross Join
Inner Join
An Inner Join returns only the rows where there is a match in both tables. If there is no match, the row is not included in the result set.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
INNER JOIN table2 AS b
ON a~common_field = b~common_field.
In this example, the query retrieves rows from table1 and table2 where common_field matches in both tables.
Left Outer Join
A Left Outer Join returns all rows from the left table and the matched rows from the right table. If there is no match, the result is NULL from the right table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
LEFT OUTER JOIN table2 AS b
ON a~common_field = b~common_field.
This query retrieves all rows from table1, and the matching rows from table2. If there is no match, it shows NULL for columns from table2.
Right Outer Join
A Right Outer Join is similar to a Left Outer Join but retrieves all rows from the right table and the matched rows from the left table. If there is no match, the result is NULL from the left table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a
RIGHT OUTER JOIN table2 AS b
ON a~common_field = b~common_field.
This query retrieves all rows from table2, and the matching rows from table1. If there is no match, it shows NULL for columns from table1.
Cross Join
A Cross Join returns the Cartesian product of the two tables, meaning it combines each row of the first table with each row of the second table.
Example:
SELECT a~field1, b~field2
INTO TABLE @DATA(result)
FROM table1 AS a,
table2 AS b.
This query retrieves all possible combinations of rows from table1 and table2.
When to Use Each Join Type
– Inner Join: Use when you only need rows with matching values in both tables.
– Left Outer Join: Use when you need all rows from the left table, regardless of whether there is a match in the right table.
– Right Outer Join: Use when you need all rows from the right table, regardless of whether there is a match in the left table.
– Cross Join: Use when you need all possible combinations of rows from both tables.
Author : Aniket Pawar, 9373518385