Oracle Max(Date) function usage-SQL max date

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

Max() function in sql can be used to get maximum value of two or more dates.Max(Date) function is useful in retrieving the maximum value of date from a record set or column or result set etc.The following examples shows the usage of Max() function to find out maximum value of dates.

Read more about SQL MAX() function here.
Read more about oracle DATE here >> DATE Data type,TO_DATE ,TO_CHAR ,TO_TIMESTAMP,timestamp format,DATE vs TIMESTAMP ,comparing dates,DATE Format

Example for Max(date):

Step 1: Create table DATETABLE as follows ,which is having a DATE column as ‘thedate’.

SQL>  create table DateTable (id number, thedate date);
Table created

STEP 2: Insert the following records in DATETABLE.

SQL> insert into dateTable values(1, sysdate-1);
SQL> insert into dateTable values(2, sysdate);
SQL> insert into dateTable values(3, sysdate+1);
SQL> insert into dateTable values(4, sysdate+2);

4 row inserted

STEP 3: Query the table for Id of the row which is having the maximum value of ‘thedate’.

SQL>  select id from datetable where thedate =(select max(thedate) from datetable);
ID
4

Read more about SQL MAX() function here.
Read more about oracle DATE here >> DATE Data type,TO_DATE ,TO_CHAR ,TO_TIMESTAMP,timestamp format,DATE vs TIMESTAMP ,comparing dates,DATE Format

Related Articles,

Technorati Tags:
, , , , ,

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

2 thoughts on “Oracle Max(Date) function usage-SQL max date

  1. 16may1989

    SQL> insert into dateTable values(1, sysdate-1);
    SQL> insert into dateTable values(2, sysdate);
    SQL> insert into dateTable values(3, sysdate+1);
    SQL> insert into dateTable values(4, sysdate+2);
    SQL> insert into dateTable values(4, sysdate+2);
    SQL> insert into dateTable values(4, sysdate+2);

    how to get the max date ? i only want 1 value 
    for example answer – 
    ID 4 only , not ID 4 , 5, 6
    how can i group them into 1 ?

    Reply
  2. shash

    SQL> insert into dateTable values(1, sysdate-1);
    SQL> insert into dateTable values(2, sysdate);
    SQL> insert into dateTable values(3, sysdate+1);
    SQL> insert into dateTable values(4, sysdate+2);
    SQL> insert into dateTable values(5, sysdate+2);
    SQL> insert into dateTable values(6, sysdate+2);

    how to get the max date ? i only want 1 value 
    for example answer – 
    ID 4 only , not ID 4 , 5, 6
    how can i group them into 1 ?

    Reply

Leave a Reply to shash Cancel reply

Your email address will not be published. Required fields are marked *

Paged comment generated by AJAX Comment Page