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,
- Oracle PL/SQL: To_Timestamp Function | Datetime Format ModelsOracle DATE vs TIMESTAMP |Comparing Oracle DATE and TIMESTAMP Datatypes
- Oracle to_char function and usage
- Using oracle date format |Using the DATE Format Mask in pl/sql
- Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql
- ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error
- PL/SQL EXTRACT function for oracle datetime
- Oracle Dates and Times |SYSDATE|CURRENT_TIMESTAMP |SYSTIMESTAMP |DBTIMEZONE |LOCALTIMESTAMP
- oracle to_date | Oracle/PLSQL: To_Date Function
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 ?
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 ?