Oracle: '= ANY()' vs. 'IN ()'

后端 未结 9 1372
难免孤独
难免孤独 2020-12-01 03:37

I just stumbled upon something in ORACLE SQL (not sure if it\'s in others), that I am curious about. I am asking here as a wiki, since it\'s hard to try to search symbols in

9条回答
  •  遥遥无期
    2020-12-01 03:49

    IN- Equal to any member in the list
    ANY- Compare value to **each** value returned by the subquery
    ALL- Compare value to **EVERY** value returned by the subquery
    
    ANY() - more than minimum
    =ANY() - equivalent to IN
    >ALL() - more than the maximum
    

    eg:

    Find the employees who earn the same salary as the minimum salary for each department:

    SELECT last_name, salary,department_id
    FROM employees
    WHERE salary IN (SELECT MIN(salary)
                     FROM employees
                     GROUP BY department_id);
    

    Employees who are not IT Programmers and whose salary is less than that of any IT programmer:

    SELECT employee_id, last_name, salary, job_id
    FROM employees
    WHERE salary  'IT_PROG';
    

    Employees whose salary is less than the salary ofall employees with a job ID of IT_PROG and whose job is not IT_PROG:

    SELECT employee_id,last_name, salary,job_id
    FROM employees
    WHERE salary  'IT_PROG';
    

    ....................

    Hope it helps. -Noorin Fatima

提交回复
热议问题