1
1
13124291322019-02-23 18:52:22
MySQL
1312429132, 2019-02-23 18:52:22

SQL. How to get one from two given queries?

Request #1:

select s.salary from salaries as s
join employees as e on e.emp_no = s.emp_no
where s.to_date = '9999-01-01' and e.gender = 'F'
order by salary desc limit 1

Request #2:
select s.salary from salaries as s
join employees as e on e.emp_no = s.emp_no
where s.to_date = '9999-01-01' and e.gender = 'M'
order by salary desc limit 1

Query Purpose: Get the highest paid female/male employee.
Is it possible to combine these two queries into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-02-23
@1312429132

select MAX(s.salary) from salaries as s
join employees as e on e.emp_no = s.emp_no
where s.to_date = '9999-01-01'
GROUP BY e.gender

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question