Difference between IN and ANY operators in SQL

后端 未结 10 1828
無奈伤痛
無奈伤痛 2020-12-23 11:14

What is the difference between IN and ANY operators in SQL?

10条回答
  •  青春惊慌失措
    2020-12-23 11:52

    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.

提交回复
热议问题