Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Min in left outer join condition

0 Kudos

Hi everybody,

I'm trying to use MIN in on condition of left outer join in abap , but it's faield;is it possible in abap?

SELECT t1.foo, t2.bar
  FROM table1 AS t1
LEFT OUTER
  JOIN table2 AS t2
    ON t2.table1_id = t1.id  
   AND t2.datefld = 
       ( SELECT MIN(datefld)
           FROM table2
          WHERE table1_id = t1.id )

thanks !
1 ACCEPTED SOLUTION

DoanManhQuynh
Active Contributor

I think you can select min(..) to get the min record, like this:

SELECT 
SPFLI~CARRID AS CARRID,
SPFLI~CONNID AS CONNID,
MIN( DISTINCT SFLIGHT~SEATSOCC ) AS SEATSOCC
FROM SPFLI LEFT OUTER JOIN SFLIGHT ON ( SPFLI~CARRID = SFLIGHT~CARRID AND
SPFLI~CONNID = SFLIGHT~CONNID )
INTO TABLE @DATA(SFLIGHT_TAB)
GROUP BY SPFLI~CARRID,SPFLI~CONNID.

4 REPLIES 4

raymond_giuseppi
Active Contributor

Read the online Abap documentation (In 'ON sql_cond' is written 'Subqueries cannot be used') so did you try a WHERE clause such as

  SELECT SINGLE mara~matnr marc~werks
    INTO CORRESPONDING FIELDS OF record
    FROM mara
    JOIN marc
      ON mara~matnr EQ marc~matnr
    WHERE
      marc~werks = ( SELECT MIN( werks ) FROM marc WHERE matnr = mara~matnr ).

0 Kudos

Hi Raymond,

MIN( werks )FROM marc WHERE matnr = mara~matnr ) 

in where clause change the outcome , i have " left outer join " ; if no records in t2 for where condition , sy-subrc = 4.

Maybe ,

DoanManhQuynh
Active Contributor

I think you can select min(..) to get the min record, like this:

SELECT 
SPFLI~CARRID AS CARRID,
SPFLI~CONNID AS CONNID,
MIN( DISTINCT SFLIGHT~SEATSOCC ) AS SEATSOCC
FROM SPFLI LEFT OUTER JOIN SFLIGHT ON ( SPFLI~CARRID = SFLIGHT~CARRID AND
SPFLI~CONNID = SFLIGHT~CONNID )
INTO TABLE @DATA(SFLIGHT_TAB)
GROUP BY SPFLI~CARRID,SPFLI~CONNID.

0 Kudos

Well done Quynh Doan Manh, u 're right; thanks !