Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the employee database of Fig. 2, where the primary keys are underlined.

ID: 3756044 • Letter: C

Question

Consider the employee database of Fig. 2, where the primary keys are underlined. Given an SQL query for each of the following questions.

a. Find the names of all employees who work for First Bank Corporation.

b. Find the names and cities of residence of all employees who work for First Bank Corporation.

c. Find the names, street addresses, and cities of residence of all employees who work for First Bank Corporation and earn more than $10,000.

d. Find all employees in the database who live in the same cities as the companies for which they work.

e. Find all employees in the database who live in the same cities and on the same streets as do their managers.

f. Find all employees in the database who do not work for the First Bank Corporation.

employee(employee-id, employee-name, street, city)

works(employee-id, company-id, salary)

company(company-id, company-name, city)

manages(employee-id, manager-id)

Figure 2. Employee database

Explanation / Answer

a.answer)

SELECT e.employee-name FROM employee AS e,works AS w ,company AS c where e.employee-id=w.employee-id AND w.company-id=c.company-id AND c.company-name='First Bank Corporation ';


b.answer)
SELECT e.employee-name,e.city FROM employee AS e,works AS w ,company AS c where e.employee-id=w.employee-id AND w.company-id=c.company-id AND c.company-name='First Bank Corporation' ;


c.answer)
SELECT e.employee-name,e.city,e.street FROM employee AS e,works AS w ,company AS c where e.employee-id=w.employee-id AND w.company-id=c.company-id AND c.company-name='First Bank Corporation' AND w.salary>10000 ;


d.answer)
SELECT e.employee-name,e.employee-id,e.street,e.city FROM employee AS e,works AS w ,company AS c where e.employee-id=w.employee-id AND w.company-id=c.company-id AND c.city=e.city ;


e.answer)
SELECT e.employee-name,e.employee-id,e.street,e.city FROM employee AS e,manages AS m WHERE e.employee-id=m.employee-id;

f.answer)
SELECT e.employee-name,e.employee-id,e.street,e.city FROM employee AS e,works AS w ,company AS c where e.employee-id=w.employee-id AND
w.company-id=c.company-id AND c.company-name<>'First Bank Corporation';