Wednesday, July 31, 2019

Left Outer Join

This join will select all records from the first table based on the where condition and then it will join the second table with matching condition. Here if it doesn't find any record on the second table, then also it will create single line (blank line) for the join. Left outer join always creates one line of the right table based on the left table.

PARAMETERSp_carrid TYPE spfli-carrid.
SELECT a~carrida~connida~cityfroma~cityto,
       a~fltimea~deptimea~arrtime,

       b~fldateb~priceb~currencyb~planetype

  FROM            spfli   AS a
  LEFT OUTER JOIN sflight AS b
  ON b~carrid a~carrid  AND
     b~connid a~connid

  INTO TABLE @DATA(itab)
  WHERE a~carrid   @p_carrid.

cl_demo_output=>displayitab ). 


There are number of blank lines on the right table or second table. Now we shall put on a where condition for the second table also.

PARAMETERSp_carrid TYPE spfli-carrid,
            p_curr   TYPE sflight-currency.

SELECT a~carrida~connida~cityfroma~cityto,
       a~fltimea~deptimea~arrtime,

       b~fldateb~priceb~currencyb~planetype

  FROM            spfli   AS a
  LEFT OUTER JOIN sflight AS b
  ON b~carrid a~carrid  AND
     b~connid a~connid

  INTO TABLE @DATA(itab)
  WHERE a~carrid   @p_carrid
    AND b~currency @p_curr.

cl_demo_output=>displayitab ).


Now see the output. The blank lines have gone. The second table is populated based on the where condition. Here the join condition happens for both table's where condition. It means the only matching records are populated in the join.

No comments: