highest salary in every department

Posted: June 18, 2012 in MySQL

Using Group By:

create table named mydept

CREATE TABLE `mydept` (

`deptid` int(5) NOT NULL,

`deptname` varchar(15) DEFAULT NULL,

`salary` decimal(15,2) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1

insert the following records in mydept table:

1   aaa    5000.00
2  aaa   10000.00
3  bbb   6000.00
4  bbb   8000.00
5  ccc   5000.00

6 ccc    2000.00

1) select deptname,max(salary) from mydept group by deptname

Ans: deptname  salary

aaa             10000

bbb              8000

ccc                5000

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s