Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-example SQL Max Count

Related Tutorials


 
 

Share on Google+Share on Google+

SQL Max Count

Advertisement
SQL Max Count is used to return the maximum records value of the specified column in a table.

SQL Max Count

     

SQL Max Count is used to return the maximum records value of the specified column in a table.

Understand with Example

The Tutorial illiustrate an example from 'SQL Max Count'. To elaborate example we create a table 'Stu'. The create table create a table 'Stu' with required fieldnames and datatypes respectively.

 

 

 

 

Create table Stu

Create Table Stu(Id int,Name Varchar(15),Marks int);

Insert values into Stu

The insert into is used to add the records or rows into table 'Stu'.

Insert Into Stu values(1,'Ajay',89);
Insert Into Stu values(2,'Bhanu',67);
Insert Into Stu values(4,'Rakesh',67);
Insert Into Stu values(5,'Santosh',90);
Insert Into Stu values(3,'Komal',78);
Insert Into Stu values(1,'Ajay',45);
Insert Into Stu values(2,'Bhanu',67);
Insert Into Stu values(4,'Rakesh',87);
Insert Into Stu values(5,'Santosh',40);
Insert Into Stu values(3,'Komal',71);

Stu Table

+------+---------+-------+
| Id   | Name    | Marks |
+------+---------+-------+
| 1    | Ajay    | 89    |
| 2    | Bhanu   | 67    |
| 4    | Rakesh  | 67    |
| 5    | Santosh | 90    |
| 3    | Komal   | 78    |
| 1    | Ajay    | 45    |
| 2    | Bhanu   | 67    |
| 4    | Rakesh  | 87    |
| 5    | Santosh | 40    |
| 3    | Komal   | 71    |
+------+---------+-------+

Query for Max Count

The Query given below is used to sort the records by id and returns the maximum value of the marks from table 'stu'.

select id, name ,max(marks) from stu  group by id;

 Result

+------+---------+------------+
| id   | name    | max(marks) |
+------+---------+------------+
| 1    | Ajay    | 89         |
| 2    | Bhanu   | 67         |
| 3    | Komal   | 78         |
| 4    | Rakesh  | 87         |
| 5    | Santosh | 90         |
+------+---------+------------+
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Discuss: SQL Max Count   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com