SQL: MAX Function | Oracle Max() examples

      2 Comments on SQL: MAX Function | Oracle Max() examples
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

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,

Technorati Tags:
, ,

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

2 thoughts on “SQL: MAX Function | Oracle Max() examples

  1. Pingback: Oracle: SQL MIN Function | MIN() function in SQL | SQL and PLSQL

  2. Pingback: Oracle Max(Date) function usage-SQL max date | SQL and PLSQL

Leave a Reply

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

Paged comment generated by AJAX Comment Page