SQL Query HELP pls. 1. Find the First and last names and addresses of employees
ID: 3719953 • Letter: S
Question
SQL Query HELP pls.
1. Find the First and last names and addresses of employees who work on at least one project that is not located in Stafford but works in the department that has location in Stafford.
2. For each manager of the department who has a daughter and works on a project located in Houston. Retrieve the first and last name of the manager, department name that he/she manages, and the name of the daughter. The attribute showing dependent name should be labeled as Daughter Name.
Schema:
EMPLOYEEFNAMEMINIT LNAME ADDRESS SEXI SALARY | SUPERSSN DNO BDATE 123456789 1965-01-09 333445555 1955-12-08 1968-07-19 1941-06-20 1962-09-15 4534534531972-07-31 1969-03-29 8886655551937-11-10 731 Fondren, Houston, TX 638 Voss, Houston, TX 3321 Castle 291 975 Fire Oak, Humble, TX 5631 Rice, Houston, TX 980 Dallas, Houston, TX 450 Stone, Houston, TX 333445555 Franklin Alicia 25000 987654321 999887777 987654321 Wallace Bellaire, TX 333445555 333445555 987654321 Narayan 25000 25000 Ahmad Jabbar 987987987 DEPTLOCATIONS Stafford DEPARTMENT DNAME Research Administration Headquarters DNUMBER MGRSSN 333445555 987654321 MGRSTARTDATE Bellaire rland 1995-01-01 1981-06-19 WORKS_ON ESSN PNQ HOURS 123456789 123456789 453453453 20.0 453453453 PROJECT PNAME PNUMBER PLOCATION DNUM Productz 5 rizatiorn Houston 4 Stafford 987987987 987987987 987654321 987654321 35.0 null DEPENDENT DEPENDENT NAME SEX BDATE RELATIONSHIP 333445555 333445555 333445555 987654321 123456789 123456789 123456789 Alice DAUGHTER 1983-10-25 SPOUSE SPOUSE Abner Michael Alice 1942-02-28 1988-01-04 1988-12-30 1967-05-05 DAUGHTER SPOUSEExplanation / Answer
1.
Select FNAME,LNAME,ADDRESS from Employee inner join Department on Employee.DNo = Department.DNumber inner join Works_On on Employee.SSN = Works_On.ESSN inner join Project on Works_on.PNO = Project.PNumber inner join Dept_Locations on Department.DNumber = Dept_Locations.DNumber where PLocation != 'Stafford' and DLocation = 'Stafford';
2.
Select FNAME,LNAME,DNAME,Dependent_Name as 'Daughter Name' from Employee inner join Department on Employee.DNo = Department.DNumber inner join Dependent on Employee.SSN = Dependent.ESSN inner join Works_On on Employee.SSN = Works_On.ESSN inner join Project on Works_on.PNO = Project.PNumber where Employee.SSN = Department.MGRSSN and Dependent.Relationship = 'DAUGHTER' and Plocation = 'Houston';
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.