Akul 5dbms
Akul 5dbms
PRACTICAL 5
Aim: To perform various simple MySQL queries using Select statement and Where clause.
Q0: Retrieve the birth date and address of the employees whose name is John B Smith.
Q1: Retrieve the names and addresses of all employees who work for Research department.
Q2: For every project located in Stafford, list the project number, controlling department number,
and department manager’s last name, address and birth date.
Q8: For each employee, retrieve the employee’s first and last name and the first and last name of
his/her immediate supervisor.
Q9: Select all employees’ Ssn.
Q10: Select all combinations of Employee’s Ssn and Department’s Dname.
Q13: Show the resulting salaries if every employee working on the ‘ProductX’ project is given a
10% raise.
Q16: Retrieve the name of each employee who have a dependent with the same first name and same
sex as the employee.
Q1AD: Retrieve the name of all employees in department 5 who work more than 10 hours per week
on ‘ProductX’ project.
Q2AD: List the name of all employees who have a dependent with same first name as themselves.
Queries:
Q0: Retrieve the birth date and address of the employees whose name is John B Smith.
SELECT Bdate, Address FROM EMPLOYEE WHERE Fname = 'John' AND Minit = 'B' AND
Lname = 'Smith';
Akul 11232934 CSE / 4 / C / 3
Q1: Retrieve the names and addresses of all employees who work for Research department.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname, EMPLOYEE.Address FROM
EMPLOYEE JOIN DEPARTMENT ON EMPLOYEE.Dno = DEPARTMENT.Dnumber
WHERE DEPARTMENT.Dname = 'Research';
Q2: For every project located in Stafford, list the project number, controlling department
number, and department manager’s last name, address and birth date.
SELECT PROJECT.Pnumber, PROJECT.Dnum, EMPLOYEE.Lname, EMPLOYEE.Address,
EMPLOYEE.Bdate
FROM PROJECT JOIN DEPARTMENT ON PROJECT.Dnum = DEPARTMENT.Dnumber
JOIN EMPLOYEE ON DEPARTMENT.Mgr_ssn = EMPLOYEE.Ssn
WHERE PROJECT.Plocation = 'Stafford';
Q8: For each employee, retrieve the employee’s first and last name and the first and last name
of his/her immediate supervisor.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname, SUPERVISOR.Fname, SUPERVISOR.Lname
FROM EMPLOYEE JOIN EMPLOYEE AS SUPERVISOR ON EMPLOYEE.Super_ssn =
SUPERVISOR.Ssn;
Akul 11232934 CSE / 4 / C / 3
Q13: Show the resulting salaries if every employee working on the ‘ProductX’ project is given
a 10% raise.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname, EMPLOYEE.Salary * 1.10 AS New_Salary
FROM EMPLOYEE
JOIN WORKS_ON ON EMPLOYEE.Ssn = WORKS_ON.Essn
JOIN PROJECT ON WORKS_ON.Pno = PROJECT.Pnumber
WHERE PROJECT.Pname = 'ProductX';
Akul 11232934 CSE / 4 / C / 3
Q16: Retrieve the name of each employee who have a dependent with the same first name and
same sex as the employee.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname FROM EMPLOYEE
JOIN DEPENDENT ON EMPLOYEE.Ssn = DEPENDENT.Essn
WHERE EMPLOYEE.Fname = DEPENDENT.Dependent_name AND EMPLOYEE.Sex =
DEPENDENT.Sex;
Q1AD: Retrieve the name of all employees in department 5 who work more than 10 hours per
week on ‘ProductX’ project.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname FROM EMPLOYEE
JOIN WORKS_ON ON EMPLOYEE.Ssn = WORKS_ON.Essn
JOIN PROJECT ON WORKS_ON.Pno = PROJECT.Pnumber WHERE
EMPLOYEE.Dno = 5 AND PROJECT.Pname = 'ProductX' AND WORKS_ON.Hours > 10;
Q2AD: List the name of all employees who have a dependent with same first name as
themselves.
SELECT EMPLOYEE.Fname, EMPLOYEE.Lname
FROM EMPLOYEE JOIN DEPENDENT ON EMPLOYEE.Ssn = DEPENDENT.Essn
WHERE EMPLOYEE.Fname = DEPENDENT.Dependent_name;
Result:
Various MySQL queries using Select statement and Where clause have been performed on
COMPANY database.