So I'm totally having a hard time on comprehending SQL this semester. I'm really not confident on the knowledge I have in SQL and I'm trying to work on this exercise where it says:
A SELECT statement to retrieve a list of employees with the columns DEPARTMENT_ID , DEPARTMENT_NAME , FULL_NAME, JOB_TITLE where FULL_NAME is the First name and Last name concatenated with a space between them for those employees that their Job title contains the word 'Sales'. The list must be sorted by job title and department name.
So far, I came up with this
SELECT department_id,
department_name,
first_name || ' ' || last_name as Full_name,
job_title
FROM departments d, employees e, jobs j
WHERE d.department_id=e.department_id
HAVING job_title LIKE '%Sales%';
and the error says:
Error starting at line 1 in command:
select department_id, department_name, first_name || ' ' || last_name as Full_name, job_title
from departments d, employees e, jobs j
where d.department_id=e.department_id
having job_title like '%Sales%'
Error at Command Line:1 Column:8
Error report:
SQL Error: ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Any tips and help will do.
"Column 8" in your command is the eighth character, the department_id field. You're SELECTing the column department_id from two tables which both have that column; it's ambiguous because the parser sees two possible values for department_id (the one from departments and the one from employees), even though we know based on your WHERE clause that those values will be identical. You have to pick one:
select d.department_id, ...
Specify whether it's e.department_id or d.department_id (etc) for the selected fields
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With