We cannot easily compute the set of employees that earn more than
every employee of Small Bank Corporation, but we can compute the set
of employees that earn less than some employees of Small Bank
Corporation.
It's not the inequalities that make a difference. (You can see this by just changing them in your σ.) It's the FOR EVERY/ALL vs FOR SOME.
A predicate is a true-or-false fill-in-the-(named-)blanks statement).
-- person [W.P] works for company [W.C] for salary [W.S]
W (W.P,W.C,W.S)
Notice that the name plus its attributes is a shorthand version of the predicate. We call the predicate of a relation variable, constant or expression its meaning.
Suppose relation expressions e & f hold the rows that make predicate expressions E & F true (respectively). The algebra operators were designed so that:
R
holds the rows satisfying R(R.X,...)
ρS(e
with attributes R.X
)
holds the rows satisfying E with R.X replaced by S.X
e⨯f
holds the rows satisfying E AND F
e-f
holds the rows satisfying E AND NOT F
eUf
holds the rows satisfying E OR F
σ
condition
(e)
holds the rows satisfying E AND condition
πA(e)
holds the rows satisfying FOR SOME all attributes but A: E
It just so happens that for each small change in relation there is a small change in meaning. Notice that the list does not include expression ~(e)
("complement") which holds rows where NOT E, ie the rows that aren't in e. Because (in general) that's a lot of rows and impractical to calculate. But it turns out that if we never want those rows as a query result (and we generally don't) then we can rewrite using other operators. FOR ALL A: E means NOT FOR SOME A: NOT E. So queries involving FOR ALL are complicated and we can't (in general) have FORALL on the outside. The original meaning isn't complicated, but we have to rearrange it to a complex phrasing that is calculated by a complex relation expression.
So the answer is, it happens that the relation where FOR SOME A: E is simple to calculate and visualize, but the relation where FOR ALL A: E uses complicated calls of inexpensive opertators to calculate inexpensively and isn't a human-obvious rearrangement of e.
(There are various special cases of using FOR ALL that translate directly to simple calls of various "division" operators. But then the special cases do not have simple meanings! It turns out that it is simpler to express FOR ALL queries using relation subset operators.)
(See my answers & their questions here re predicates & algebra and here re sql.)
What does works.salary <= d.salary exactly do? Does it loop for every
works.salary entity through all the d.salary entities and look if it
is <= for ALL d.salary entities?
It appears in a σ call (selection/restriction). The call outputs rows that make the argument relation value true and that make the condition (a predicate) true. Ie the rows that make the AND (conjunction) of the two predicates true. Ie the roews in its input that make the condition true. All it has to do with the overall result is that it calculates something along the way.
You can translate your query to natural language. Although the way you wrote it is by (informally) translating if from natural language. That will turn out to be talking about a maximum. Eg temp is rows that satisfy:
-- temp ← ∏works.person_name(σp(works⨯ρd(works)))
FOR SOME works.company_name, works.salary,
d.person_name, d.company_name, d.salary:
person [works.person_name] works for company [works.company_name]
for salary [works.salary]
AND person [d.person_name] works for company [d.company_name]
for salary [d.salary]
AND [works.salary] <= [d.salary]
AND ...
This is rows where person [works.person_name] works for company [works.company_name] for salary [works.salary] and person [d.person_name] works for company [d.company_name] for some salary [d.salary] AND [works.salary] <= [d.salary] AND ..., for some values for attributes other than works.person_name. So it's a list of people where there exists some other (≠) person with at least as big a salary at Small Bank Corporation.
(Your query would be simpler if you ignored person names and just asked for people pairs where the works-person has a smaller salary than the d-person. If their salary is not equal to yours then they're not you.)