What are the equivalent joins written in the Oracle’s old join syntax of these queries?
SELECT first_name, last_name, department_name, job_title FROM employees e RIGHT JOIN departments d ON(e.department_id = d.department_id) RIGHT JOIN jobs j USING(job_id);
–>106 rows returned
SELECT first_name, last_name, department_name, job_title FROM employees e RIGHT JOIN jobs j ON(e.job_id = j.job_id) RIGHT JOIN departments d USING(department_id);
–> 122 rows returned
Advertisement
Answer
I would do something like this (for the first query) – making explicit the fact that a multiple join is, by definition, an iteration of joins of two tables (or more generally “rowsets”) at a time. Think of it as “using parentheses explicitly”.
select first_name, last_name, department_name, job_title from ( select first_name, last_name, job_id, department_name from employees e, departments d where e.department_id (+) = d.department_id ) sq , jobs j where sq.job_id (+) = j.job_id ;
This can be rewritten (perhaps) using a single SELECT statement, with more WHERE conditions – but the query will be less readable; it wont’ be quite as clear what it is doing.