This exercise is from W3Schools.
Given 2 tables, Employees
and Jobs
, find the names (first_name, last_name), salary of the employees whose salary is equal to the minimum for their job grade.
The solution given is:
SELECT
first_name, last_name, salary
FROM
employees
WHERE
employees.salary = (SELECT min_salary
FROM jobs
WHERE employees.job_id = jobs.job_id);
The INNER JOIN subquery
SELECT min_salary
FROM jobs
WHERE employees.job_id = jobs.job_id
shouldn't work since the Employees
table has not been CROSSJOIN'ed with the Jobs
table. However it seems to work while its been nested within a parent call. Are the tables automatically crossjoined when they are called in this manner?
Can someone enlighten me how this works?
EDIT:
This exercise instructs you to do it using subqueries, but I've found a method that makes way more sense:
SELECT
first_name, last_name, salary
FROM
employees, jobs
WHERE
salary = min_salary
AND employees.job_id = jobs.job_id;