Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Dbms Answers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Question 1

1. Retrieve the name and address of all employees who work for the ‘Research’ department

SELECT FNAME, EMPLOYEE.NAME, ADDRESS

FROM EMPLOYEE, DEPARTMENT

WHERE DEPARTMENT.NAME = ‘Research’ AND

DEPARTMENT.DNUMBER = EMPLOYEE.DNUMBER;

2. For each employee, retrieve the employee’s first and last name, and the first and last name
of his or her immediate supervisor.

SELECT E.FNAME, E.LNAME, S.FNAME, S.LNAME

FROM EMPLOYEE AS E, EMPLOYEE AS S

WHERE E.SUPERSSN = S.SSN;

3. Retrieve the name of each employee who works on allthe projects controlled by department
number 5

SELECT FNAME, LNAME

FROM EMPLOYEE

WHERE NOT EXISTS

( (SELECT PNUMBER

FROM PROJECT

WHERE DNUM = 5)

EXCEPT

(SELECT PNO

FROM WORKS_ON

WHERE SSN = ESSN) );

4. Make a list of all project numbers for projects that involve an employee whose last name is
'Smith' as a worker or as a manager of the department that controls the project.

(SELECT DISTINCT PNUMBER

FROM PROJECT, DEPARTMENT, EMPLOYEE

WHERE DNUM = DNUMBER AND MGRSSN = SSN AND LNAME = ‘Smith’)

UNION

(SELECT DISTINCT PNUMBER

FROM PROJECT, WORKS_ON, EMPLOYEE

WHERE PNUMBER = PNO AND ESSN = SSN AND LNAME = ‘Smith’);


Another way
SELECT DISTINCT PNUMBER

FROM PROJECT

WHERE PNUMBER IN (SELECT PNUMBER

FROM PROJECT, DEPARTMENT, EMPLOYEE

WHERE DNUM = DNUMBER AND MGRSSN = SSN AND

LNAME = ‘Smith’)

OR

PNUMBER IN (SELECT PNO

FROM WORKS_ON, EMPLOYEE

WHERE ESSN = SSN AND LNAME = ‘Smith’);

5. Retrieve the SSN of all employees who work on project number 1,2, or 3
SELECT DISTINCT ESSN
FROM WORKS_ON
WHERE PNO IN (1,2,3);

Question 2(all are simple queries)


Question 3
(1&2 are simple and most of you have done correctly)

3) (sample question for CIAT 2) Find the names, street address, and cities of residence for all
employees who work for

'First Bank Corporation' and earn more than $10,000.

select employee.employee-name, employee.st r eet , employee.cit y f r om

employee, wor ks

wher e employee.employee-name=wor ks.employee-name

and company-name = ' Fir st Bank Cor por at ion' and salar y > 10000)

4) Find the names of all employees in the database who earn more than every employee

of 'First Bank Corporation'. Assume that all people work for at most one company.

select employee-name

f r om wor ks

wher e salar y > all (select salar y

f r om wor ks

wher e company-name = ' First Bank Cor por at ion' )

You might also like