What is the difference between IN and ANY operators in SQL?
IN - Equals to Anything in the List
ANY - Compares Value to Each Value Returned by the Sub Query.
ALL - Compares Value To Every Value Returned by the Sub Query.
For Example:
IN:
Display the Details of all the Employees Whose Salaries are Matching with the Least Investments of Departments?
Select Ename, Sal, Deptno
from Emp
Where Sal IN (Select Min(Sal)
From Emp
Group By Deptno);
ANY:
< ANY Means Less Than The Maximum Value in the List.
Get The Details of All Employees Who are Earning Less Than The Highest Earning Employee Controlling Other Emp?
Select Empno, Ename, Job, Sal
From Emp
Where Sal < Any (Select Distinct MGR
From Emp);
> ANY Means More Than The Minimum Value in the List.
Get The Details Of All Emps Who are Earning more than the least paid of Department 10?
Select Empno, Ename, Job, Sal
From Emp
Where Sal > Any (Select Min(Sal)
From Emp
Where Deptno 10);
=ANY is Equivalent to In Operator.
Note: SOME is also used instead of ANY.