I need help with a few SQL database codes to return some resutls! The queries th
ID: 3606403 • Letter: I
Question
I need help with a few SQL database codes to return some resutls! The queries that I need to write are described below this and the tables I have are described below the questions.
--------------------
*Write a query that consists of one block only. For every employee who works for a department that is different from his supervisor's department: Find his ssn, lname, department number; and his supervisor's ssn, lname, and department number. Sort the results by ssn.
Hint: This is a DIVISION query
*For every employee who works on every project that is controlled by department 4: Find the ssn and lname. Sort the results by lname
-----------------
Tables
-
employee, department, dept_locations, project, works_on, dependent
-
Keys in order of tables
-
fname, lname, ssn, bdate, address, sex, super_ssn, dno
dnumber, dname, mgrssn, mgrstartdate
dnumber, dlocation
pname, pnumber, plocation, dnum
essn, pno, hours
essn, dependent_name, sex, bdate, relationship
Explanation / Answer
select e.ssn, e.lname, e.dno, sv.ssn, sv.lname, sv.dno from employee e, employe s where e.super_ssn = s.ssn and e.dno s.dno order by e.ssn; select e.ssn, e.lname from employee e,project p,works_on w,department d where e.ssn=w.essn and w.pno=p.pnumber and p.dnum=d.dnumber and d.dnumber=4 order by e.lname;Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.