My understanding of the logical order of execution of sql query is that
FROM
which gives us the base set of data
WHERE
which filters the base set data
SELECT
returning the filtered data
I am not able to wrap my head around in the working of this query which contains a subquery:-
SELECT name,salary
FROM salary a
WHERE (SELECT count(*)
FROM salary b
WHERE b.salary > a.salary) = 1
I mean here, when WHERE
is filtering the data out, but there is a different SELECT
, FROM
, WHERE
respectively which is returning a data which is then compared with outer query's WHERE
condition.
so how it is associating with the outer query?
I know this is a bit intuitive but still, a flow of execution to give a proper understanding would be great.