Answer the question
In order to leave comments, you need to log in
How to compose a join using query with an intermediate table?
Good afternoon. I can't figure out the task, please help
• Display a two-column table (HR schema). In the first column, the name and surname of the employee (first_name and last_name), separated by one space. In the second column, the address of the department for which the employee works. Specify the address of the department in the form city||''||street_address. Both fields are contained in the location table. (Because the employes and locations tables do not have common fields, use the departments table as an intermediate table). When compiling the query, use the join type …JOIN… USING
The problem is that I do not understand how to use the "intermediate table"
table employees: first_name, last_name, department_id
locations: city, street_address, location_id
departments: location_id, department_id
SELECT first_name||' '|| last_name, city||''||street_address
FROM employees JOIN locations USING(department_id, location_id)
Answer the question
In order to leave comments, you need to log in
SELECT E.FIRST_NAME,
E.LAST_NAME,
L.STREET_ADDRESS
FROM HR.EMPLOYEES E
LEFT JOIN DEPARTMENTS D ON D.DEPARTMENT_ID = E.DEPARTMENT_ID
LEFT JOIN LOCATIONS L ON L.LOCATION_ID = D.LOCATION_ID;
SELECT E.FIRST_NAME,
E.LAST_NAME,
L.STREET_ADDRESS
FROM HR.EMPLOYEES E
LEFT JOIN DEPARTMENTS D USING (DEPARTMENT_ID)
LEFT JOIN LOCATIONS L USING (LOCATION_ID);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question