Hello i don't understant how correlated subqueries work under the hood. I have two tables an i want to check if two values are equal if some value of second one if some value from first table is equal to value from second table. My code to do that is:
SELECT first_name, last_name, salary
FROM employees
WHERE employees.salary = (SELECT min_salary
FROM jobs
WHERE employees.job_id = jobs.job_id);
How does it exactly work that it knows if the job_id is correct for employees Object when it comes to comparing salary in outer query? Is it iterating over every value and its passing the value to alias.Object?
Let's say the value of the inner query is 2500. What if there is employee who earn 2500 but min_salary for his job_id would be 2000? How does this query knows when it's right or not?
If someone needs more details then everything is better explained here: https://www.w3resource.com/mysql-exercises/subquery-exercises/find-the-names-salary-of-the-employees-whose-salary-is-equal-to-the-minimum-salary-for-their-job-grade.php