ANY and ALL

The following table summarizes the equivalents for ANY and ALL:

 

Let’s have a look for each case:

< ANY  ( LESS THAN THE HIGHEST )

select * from employees where salary < ANY 
(select salary from employees where department_id = 80) ;

The query will show all employees with a salary less than the highest salary in department 80

 

> ANY  ( MORE THAN THE LOWEST )

select * from employees where salary > ANY 
(select salary from employees where department_id = 80) ;

The query will show all employees with a salary more than the lowest salary in department 80

 

= ANY  ( EQUIVALENT TO IN )

select * from employees where salary = ANY 
(select salary from employees where department_id = 80) ;

The query will show all employees with a salary equal to any salary in department 80

 

> ALL ( MORE THAN THE HIGHEST )

select * from employees where salary > ALL 
(select salary from employees where department_id = 80) ;

The query will show all employees with a salary more than the highest salary in department 80

 

< ALL ( LESS THAN THE LOWEST )

select * from employees where salary < ALL 
(select salary from employees where department_id = 80) ;

The query will show all employees with a salary less than the lowest salary in department 80

 

 

 

 

Leave a comment

Your email address will not be published. Required fields are marked *