title: SQL MAX function strange behaviour
body: <p>Stackoverflow, hello.
  Having the following problem.
  Suppose having a query that returns the following :<img src="https://i.stack.imgur.com/AK6rx.png" alt="a query"></p>
  
  <p>When I try  "select max(col1), max(col2)" on it, it returns me:</p>
  
  <p><img src="https://i.stack.imgur.com/nr73q.png" alt="enter image description here"></p>
  
  <p>Whent I try "select max(col2),max(col1)" it returns me:</p>
  
  <p><img src="https://i.stack.imgur.com/qyI2n.png" alt="enter image description here"></p>
  
  <p>Do you have any ideas of what is happening here?</p>
  
  <p>The query that gives the problem is </p>
  
  <pre><code>select max(col2),max(col1)
  from (
  
  SELECT 
          NVL(IS_IN_OPEN_BR, 0)                             AS col1,
          NVL(IS_IN_OPEN_ISR, 0)                            AS col2
        FROM
          (
          SELECT DISTINCT PRD_DEV_CODE AS DEV_CODE_ISR,
            PRD_GRP_CODE               AS GRP_CODE_ISR,
            1                          AS IS_IN_OPEN_ISR
          FROM ATL_ADM.PRODUCT PRD
          INNER JOIN ATL_ADM.SB_REQ SR
          ON PRD.PRD_ID = SR.SBR_PRD_ID
          INNER JOIN ATL_ADM.LIB_REPLENISH_REQ LSR
          ON LSR.LSR_ID         = SR.SBR_LSR_ID
          WHERE LSR.LSR_STATUS &lt;&gt; 'CLOSED'
          GROUP BY PRD_DEV_CODE,
            PRD_GRP_CODE
          ) ISR
        FULL OUTER JOIN
          (
          SELECT DISTINCT PRD.PRD_DEV_CODE DEV_CODE_SHIP,
            PRD.PRD_GRP_CODE AS GRP_CODE_SHIP,
            NVL( MAX (SHP.SHIP_SHIPDATE), MAX (SHP.SHIP_UPDDATET)) LAST_SHIP_DATE
          FROM ATL_ADM.SB_REQ SR
          JOIN ATL_ADM.SHIPMENT SHP
          ON SR.SBR_ID = SHP.SHIP_SBR_ID
          JOIN ATL_ADM.PRODUCT PRD
          ON PRD.PRD_ID        = SR.SBR_PRD_ID
          WHERE SR.SBR_TYPE    = 'FLA'
          AND SHP.SHIP_STATUS IN ('SHIPPE', 'MANDEV')
          GROUP BY PRD.PRD_DEV_CODE ,
            PRD.PRD_GRP_CODE
          ) SHIPS ON DEV_CODE_ISR = DEV_CODE_SHIP
        FULL OUTER JOIN
          (
              SELECT DISTINCT 
                  PRODUCT.PRD_DEV_CODE  DEV_CODE_BR,
                  PRODUCT.PRD_GRP_CODE GRP_CODE_BR,
                  1 IS_IN_OPEN_BR
              FROM ATL_ADM.PRODUCT
              JOIN ATL_ADM.SB_REQ
              ON PRODUCT.PRD_ID = SB_REQ.SBR_PRD_ID
              JOIN ATL_ADM.REQT_SET
              ON REQT_SET.REQTS_ID = SB_REQ.SBR_RS_ID
              JOIN ATL_ADM.BRIEF
              ON BRIEF.BR_ID = REQT_SET.REQTS_BR_ID
              WHERE BRIEF.BR_STATUS_CODE NOT IN ('CLOSED', 'CANCEL')
              GROUP BY PRODUCT.PRD_GRP_CODE,
              PRODUCT.PRD_DEV_CODE,
              BRIEF.BR_STATUS_CODE
          ) BRS ON DEV_CODE_BR = DEV_CODE_SHIP)
  </code></pre>