I have this SQL query can anyone help me with the order of execution like which clause is run first and then last:
SELECT COUNT(*),
(SELECT COUNT(*)
FROM recent_grads
)
FROM recent_grads
WHERE ShareWomen > (SELECT AVG(ShareWomen)
FROM recent_grads
);
I know the "FROM" clause in line number 5 is run first because it tells our query that the table or dataset we will be using is called "recent_grads".
Then I think the "WHERE" clause is run second and in the WHERE clause, the subquery is run first. When the subquery is run then the subquery is replaced by a certain value. Then we have a proper filter statement.
I think the third clause that is run is the "SELECT" clauses from the first line and in that clause, the statement " SELECT COUNT()" is run first which returns the number of filtered rows. Then the subquery is run which returns the number of rows in the dataset without filter, so the original amount of rows.
Can someone please let me know if my order of execution is right, I am not sure about the third one when the "SELECT" clause is called, I wanna know if the subquery in the SELECT clause gets executed first or the COUNT() function itself gets executed first.