Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL - Maximum from two select statements

I have two select statements that find the maximum salary for a specific role. Now I want to have the maximum of the two returns of those select statements. Think about the following code:

SELECT MAX(SALARY) 
  FROM TABLE1 
 WHERE ROLE = 'MANAGER'

SELECT MAX(SALARY) 
  FROM TABLE1 
 WHERE ROLE = 'DEVELOPER'; 

At the end I want the maximum of these two numbers.

How would I do all this in one query?

Have two selects for maximum, then compare those maximums and give the maximum of the two maximums?

like image 481
oneiros Avatar asked Dec 19 '11 01:12

oneiros


Video Answer


2 Answers

If you want maximum from more job titles, add that job title in "IN" array. No need to write one select statement for each job title.

SELECT MAX(SALARY) FROM TABLE1 WHERE ROLE IN ('MANAGER','DEVELOPER')
like image 122
Somnath Muluk Avatar answered Nov 11 '22 21:11

Somnath Muluk


Since both selects read from the same table, you can do this:

SELECT MAX(SALARY) FROM TABLE1 WHERE ROLE = 'MANAGER' OR ROLE = 'DEVELOPER'
like image 44
Sergey Kalinichenko Avatar answered Nov 11 '22 21:11

Sergey Kalinichenko