Oracle Max(Date) function usage-SQL max date

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:
, , , , ,