Professional Documents
Culture Documents
Join
[Inner] Join
Table 1 Table 2
|----|----|----|----| |----|----|----|----|----|
| A | B | C | D | | D | E | F | G | H |
|----|----|----|----| |----|----|----|----|----|
| a1 | b1 | c1 | 1 | | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | | 3 | e2 | f2 | g2 | h2 |
| a3 | b3 | c3 | 2 | | 4 | e3 | f3 | g3 | h3 |
| a4 | b4 | c4 | 3 | |----|----|----|----|----|
|----|----|----|----|
Inner Join
|----|----|----|----|----|----|----|----|
| A | B | C | D | E | F | G | H |
|----|----|----|----|----|----|----|----|
| a1 | b1 | c1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | e1 | f1 | g1 | h1 |
| a4 | b4 | c4 | 3 | e2 | f2 | g2 | h2 |
|----|----|----|----|----|----|----|----|
[Inner] Join example
START-OF-SELECTION.
SELECT spfli~connid scarr~carrname
INTO TABLE gt_connid
FROM spfli
JOIN scarr ON spfli~carrid = scarr~carrid
WHERE spfli~connid IN s_connid.
Table 1 Table 2
|----|----|----|----| |----|----|----|----|----|
| A | B | C | D | | D | E | F | G | H |
|----|----|----|----| |----|----|----|----|----|
| a1 | b1 | c1 | 1 | | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | | 3 | e2 | f2 | g2 | h2 |
| a3 | b3 | c3 | 2 | | 4 | e3 | f3 | g3 | h3 |
| a4 | b4 | c4 | 3 | |----|----|----|----|----|
|----|----|----|----|
START-OF-SELECTION.
SELECT spfli~connid scarr~carrname
INTO TABLE gt_connid
FROM spfli
LEFT JOIN scarr ON spfli~carrid = scarr~carrid
WHERE spfli~connid IN s_connid.
One thing to keep in mind when using INNER The OUTER JOIN different from the INNER
JOIN is that, only the rows that are common on JOIN, even if in secondary table doesn’t find a
both tables included in JOIN will be selected, so if row common to primary table, still will get the
in second table the JOIN doesn’t find a common row from the primary table, so in some cases is
row to primary table, than no data is selected even more useful to use OUTER JOIN than INNER
from the primary table. JOIN.
Exercise
The WHERE condition is performed for each line of the internal table.
For each line, the system selects the lines from the database table that satisfy the
condition.
The result set is the union of the individual selections for each line of the internal table.
Duplicate lines are automatically eliminated from the result set.
If itab is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
START-OF-SELECTION.
START-OF-SELECTION.
5. Display the carrier name, country from, country to for S_CARRID . Use the
FOR ALL ENTRIES option for selection.
3. From the flights already selected, display the flight with the most empty seats (SEATSMAX – SEATSOCC).
Please use an intermediate internal table GT_SFLIGHT_DET with the following structure
CARRID (table SFLIGHT)
CONNID (table SFLIGHT)
FLDATE (table SFLIGHT)
SEATSDIF (table SFLIGHTS)
DIF_FLAG (CHAR1)