Question

I need the query for the following ER diagram(It is incomplete, I guess your seniority will help you understand the association well)

Query I need is - list of all employee work phone numbers(type 'W') who work in 'tech' department.

Also, Please let me know if the PK and FK are correctly normalized.


Note: For a primary key, i've mentioned PK right next to the column name and for a foreign key i used FK_ (Table Name).


What I've tried so far

select e.emp_id, e.lname from 
Employee e join contactInfo c on e.emp_id = c.emp_id 
join phones p on c.contid = p.cont_id 
join phonetype pt on pt.phoneType_id = p.phoneType_id 
join Department d on d.dept_id = e.dept_id
where dept_id = 'tech' and pt.phoneType_id = 'W'

Thank you.

enter image description here

Was it helpful?

Solution

I think the problem was in the last line of your querywhere you used "dept_id" and "phoneType_id". Those are probably integer values, not text. Here's my proposed fix:

select e.emp_id, e.lname from 
Employee e join contactInfo c on e.emp_id = c.emp_id 
join phones p on c.contid = p.cont_id 
join phonetype pt on pt.phoneType_id = p.phoneType_id 
join Department d on d.dept_id = e.dept_id
where d.type = 'tech' and pt.type = 'W'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top