1

I have a small question, how can I get highest salary from male and female column.

------+----------------+----------------+
Id.         Gender.           Salary
-----+-----------------+----------------+
1.           F.               3000
2.           M.               4000
3.           F.               3500
4.           M                3999

This is what I have tried

SELECT MAX(Salary) AS max_salary
FROM emp
GROUP BY Salary
HAVING 

I don't know furthur how to achieve.

I have posted this from my mobile phone so please help me by editing the question.

Please help as my MySQL knowledge is limited.

BenM
  • 52,573
  • 26
  • 113
  • 168
  • Show your table structure or you can use employee type in having clause but i will prefer to user where clause before group by clause. – Rajan Mishra Sep 09 '17 at 08:02
  • Do you want to get different results? As in, highest salary for male column, and highest from female column OR highest salary for both columns? – Samuel Asor Sep 09 '17 at 08:04

2 Answers2

3

You can use MAX(), and then GROUP BY on the Gender field to achieve this:

SELECT MAX(Salary) AS max_salary,
       Gender
FROM emp
GROUP BY Gender

SQLFiddle Demo

BenM
  • 52,573
  • 26
  • 113
  • 168
0

Execute:

mysql> select gender,max(salary) from [tablename] group by gender;

As per your usecase, the original table:

enter image description here

And the resultset:

enter image description here

Some hands-on on group by [MySQL Official Documentation]

Yusuf Hassan
  • 1,933
  • 1
  • 12
  • 21
  • 3
    Please. No images. – Strawberry Sep 09 '17 at 08:24
  • 2
    For clarity, @Strawberry means please include code as [formatted text](https://stackoverflow.com/help/formatting) instead of images. – Wolfie Sep 09 '17 at 09:08
  • Got it. But I still cannot comprehend including images warranted a downvote. – Yusuf Hassan Sep 09 '17 at 09:24
  • 1
    Your answer is not accessible to people using screen readers. – Martin Smith Sep 09 '17 at 11:58
  • The first thing I provided was the code snippet which can be easily copied or translated. It's easier to visualise things at times to comprehend. If I would just have pasted pictures, then the content in the link shared by @Will would have been justified. Sharing the code and showing what it does, isn't that bad an idea. – Yusuf Hassan Sep 12 '17 at 17:53