• Sharebar

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

 
SEO Powered by Platinum SEO from Techblissonline