Lets look at another way of querying with JOIN statement. Just to recap from previous post that JOIN statement aka INNER JOIN return rows when there is at least one match in BOTH tables
select e.emp_name as "Employee Name" , d.dept_name "Department Name" from employee e , department d where e.emp_dept_id = d.dept_id and d.dept_budget > 500000;
So what is the difference compared to what we have looked at last time? The difference is slight , the main logic stays the same but how we name the names have changed. take a look at the second line
from employee e , department d
Here we are saying “employee” table from now on will be referenced by “e” for the lifetime of the SQL statement. If you come from traditional programming background , like me , you might find it odd that “e” can be used on the first line yet it is only defined in the second line. You definitely cannot use a variable that has not been defined!
Anyway , besides that weirdness , every other part remains the same. Of course they are now “e.emp_name” instead of “employee.emp_name”. This query will return ,
| Employee Name | Department Name |
|---|---|
| Michael Bay | Asia |
| John Evan | Finance |
| Christine May | Sales |
| George Chan | Asia |