A
A
albertalexandrov2019-04-11 19:57:31
SQL
albertalexandrov, 2019-04-11 19:57:31

Normal example ALL?

Hello everyone!)
I'm not quite aware of the ALL operator. Here's an example :

SELECT 
    first_name, last_name, salary
FROM
    employees
WHERE
    salary > ALL (SELECT 
            salary
        FROM
            employees
        WHERE
            department_id = 2)

Here, the subquery contains all the salaries of employees of the department (department) with id = 2. The external query contains employees of all departments whose salary is higher than all salaries of employees of the 2nd department, that is, higher than the highest salary.
Why not write it like this:
SELECT 
    first_name, last_name, salary
FROM
    employees
WHERE
    salary > (SELECT 
            MAX(salary)
        FROM
            employees
        WHERE
            department_id = 2)

And there are examples everywhere. Especially enters into a stupor when I see = ALL(subquery).
Am I misunderstanding something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2019-04-11
@d-stream

maybe this example will be clearer: www.sql-tutorial.ru/ru/book_using_any_all_keywords...
p/s/ over the past 20 years neither ANY nor ALL has ever come in handy)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question