The Max() function is another much helpful function in SQL, the MAX function returns the maximum value of an expression. Read MIN() function here.
Syntax:
SELECT MAX(expression ) FROM tables WHERE ?;
Examples: (See more example for Using MAX() function along with GROUP BY statement here. )
Step 1: Create a table ‘MyTable’ as below.
SQL> create table MyTable (name varchar2(100),address varchar2(500),id number); Table created SQL>
Step 2: Insert few rows to ‘MyTable’.
SQL> insert into mytable values ('name1','msg1',1); 1 row inserted SQL> insert into mytable values ('name2','msg2',2); 1 row inserted SQL> insert into mytable values ('name3','msg3',3); 1 row inserted SQL>
Step 3: Now let us select the maximum ‘id’ from ‘Mytable’.
SQL> select max(id) from mytable; MAX(ID) 3
Step 4: Now let us retrive the complete row with maximum values of ‘id’;
SQL> select * from mytable where id = (select max(id) from mytable); NAME MSG ID name3 msg3 3< SQL>
Related Articles,
- Oracle Decode Function | Use PLSQL DECODE function to handle NULL and default values
- SQL: MAX Function | SQL Max examples
- SQL GROUP BY Statement | SQL GROUP BY Clause examples
- NVL | Oracle/PLSQL: NVL Function
- SUBSTR functions | Oracle/PLSQL: Substr Function
- Oracle/PLSQL: Instr Function |INSTR functions |Case sensitive search
- Oracle pl/sql error: ORA-06502: PL/SQL: numeric or value error:
- Oracle pl/sql error: ORA-06512
- ORA-12154: TNS:could not resolve the connect identifier specified
- Oracle timestamp format milliseconds| Oracle Date format
Pingback: Oracle: SQL MIN Function | MIN() function in SQL | SQL and PLSQL
Pingback: Oracle Max(Date) function usage-SQL max date | SQL and PLSQL