DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: min(max+max) on 2 tables

  1. #1
    Join Date
    Aug 2000
    Location
    Jolo, Sulu
    Posts
    639

    min(max+max) on 2 tables

    Hi Friends,

    I have two tables EMP1 and EMP2 with column hiredate.
    I want to get the mininum of the max(hiredate) of the two tables.
    Can u help me pls....

    This doesnt work:
    A.
    SELECT MIN(SELECT MAX(HIREDATE) FROM EMP1 UNION
    SELECT MAX(HIREDATE) FROM EMP2)
    FROM DUAL;

    B.
    SELECT MIN(HIREDATE) FROM
    (SELECT MAX(HIREDATE) FROM EMP1 UNION
    SELECT MAX(HIREDATE) FROM EMP2);

    Any other constructs pls
    Thanks a lot

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    ===
    SELECT MIN(HIREDATE) FROM
    (SELECT MAX(HIREDATE) FROM EMP1 UNION
    SELECT MAX(HIREDATE) FROM EMP2);

    ==
    PHP Code:
    You don't need UNION. Just use UNION ALL.

    SELECT MIN(HIREDATE) 
    FROM  (SELECT MAX(HIREDATE) FROM EMP1 
           UNION ALL
           SELECT MAX(HIREDATE) FROM EMP2
          );

    If there are indexes on hiredate col, then they may be used.

    Or
    select min ( (select max(hiredate) from emp1, 
                 (select max(hiredate) from emp2)
                )
    from dual;

    Here, the index will not be used. 
    Tamil

  3. #3
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    How about this?

    Code:
    SELECT MIN(hiredate) hiredate
      FROM (
     ( SELECT MAX(hiredate) hiredate
         FROM emp1 ) emp1
        UNION ALL
     ( SELECT MAX(hiredate) 
         FROM emp2 ) emp2 );

  4. #4
    Join Date
    Aug 2000
    Location
    Jolo, Sulu
    Posts
    639
    thanks falks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width