Usage of MAX in Oracle
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Usage of MAX in Oracle

  1. #1
    Join Date
    Nov 2003
    Posts
    31

    Usage of MAX in Oracle

    Hi All,

    I have a question regarding the usage of MAX in SQL.

    create table datetab (node_id, date1 timestamp, date2 timestamp);

    insert into datetab values (1, '01-FEB-1999', '03-MAR-2000');
    insert into datetab values (2, '01-FEB-1998', '03-MAR-2001');
    insert into datetab values (3, '01-FEB-1997', '03-MAR-2002');
    insert into datetab values (4, '01-FEB-1999', '03-MAR-2003');
    insert into datetab values (5, '12-MAR-1999', '03-MAR-2004');
    insert into datetab values (6, '01-MAY-1999', '03-MAR-1971');
    insert into datetab values (7, '11-JUL-1999', '03-MAR-1991');
    insert into datetab values (8, '04-FEB-1999', '03-MAR-1988');
    insert into datetab values (9, '02-FEB-1999', '03-DEC-1981');

    I am running Oracle 9.2.0.2.0.

    I need to find out the maximum date (03-MAR-2004) as well as the minimum date (03-MAR-1971) from all the data available in the table.

    I am unable to come up with a query to do the same. Any help would be greatly appreciated.

    Also, would it be possible, say, for a given node_id, to find the maximum and minimum? Ex. For node 9,
    maxdate of 02-FEB-1999 and mindate of 03-DEC-1981 should be selected.

    Many thanks,
    Sankar.
    Sankar B. Mandalika

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Code:
    select max(date2), min(date2)
    from datetab
    Code:
    select node_id,max(date2), min(date2)
    from datetab
    group by node_id
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Nov 2003
    Posts
    31
    Thanks slimdave! I appeciate your quick response. It was helpful.
    Sankar B. Mandalika

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