SELECT f_name, f_type
FROM food
WHERE f_id IN(
SELECT f_id FROM ratings
where f_rating < 3
);// this is non correlated subqueries
SELECT f_name, f_cost, f_type
FROM food
WHERE f_id IN (
SELECT f_id
FROM ratings
GROUP BY f_id
HAVING AVG(f_rating) >= 4
);// this is correlated subqueries
since both of the above query
inner query runs independently then
why is 1st one non correlated but 2nd one
correlated subqueries
The GROUP BY and WHERE clauses are the only places where we can see the subquery referencing a column in the outer query.
This is because the GROUP BY clause is used to group rows together based on the values of one or more columns,
and the WHERE clause is used to filter rows based on a condition.
If the subquery is referencing a column in the outer query, then the subquery is correlated.
This is because the sub query must be evaluated for each row in the outer query.
Is this correct?