Question

- Consider the following relational schema. - Write SQL statements for the following queries employee fname CHARACTER VARYING (15) minit CHARACTER VARYING(1) InameCHARACTER VARYING(15) essn CHARACTERO) bdate DATE address CHARACTER VARYING(50) dependent works on CHARACTERO dependent name CHARACTER VARYING(15) essn CHARACTER(9) pno NUMERIC hours NUMERIC CHARACTER() DATE CHARACTER VARYING(B) bdate CHARACTER(1) dept locations elationship salary NUMERIC super ssn CHARACTERO) dno dno NUMERIC dlocation CHARACTER VARYING(15) NUMERIC department CHARACTER VARYING(25) NUMERIC CHARACTERO) project dno mgssn mgstartdate DATE pname CHARACTER VARYING(25) pno plocation CHARACTER VARYING (15) dno NUMERIC NUMERIC 1) Retrieve the first names of employees who had worked on both the ProductX project and the Producty project. 2) Retrieve the first names of employees who had worked on the ProductX project or the ProductY project. 3) Retrieve the first names of employees who had worked on either the ProductX project or the ProductY project. 4) Retrieve the first names of employees who had worked on all projects 5) Retrieve the first names of employees who had never worked on a project.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) SELECT employee.fname

FROM employee,project,works_on

WHERE employee.essn=works_on.essn AND works_on.pno=project.pno AND project.pname = 'ProductX' AND project.pname='ProductY';

2) SELECT employee.fname

FROM employee,project,works_on

WHERE employee.essn=works_on.essn AND works_on.pno=project.pno AND project.pname = 'ProductX' OR project.pname='ProductY';

3) (SELECT employee.fname

FROM employee,project,works_on

WHERE employee.essn=works_on.essn AND works_on.pno=project.pno AND project.pname = 'ProductX' OR project.pname='ProductY')

EXCEPT

(SELECT employee.fname

FROM employee,project,works_on

WHERE employee.essn=works_on.essn AND works_on.pno=project.pno AND project.pname = 'ProductX' AND project.pname='ProductY');

4) SELECT employee.fname

FROM employee

WHERE NOT EXISTS ( SELECT pno

FROM project

WHERE NOT EXISTS ( SELECT *

FROM works_on

WHERE works_on.pno=project.pno AND employee.essn=works_on.essn ) );

5) (SELECT employee.essn

FROM employee)

EXCEPT

(SELECT employee.essn

FROM employee,essn

WHERE employee.essn=works_on.essn);

Add a comment
Know the answer?
Add Answer to:
- Consider the following relational schema. - Write SQL statements for the following queries employee fname...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED HELP IN INSERT STATEMENTS FOR THE TABLES CAN YOU PLEASE ADD SOME INSERT STATEMENTS FOR...

    NEED HELP IN INSERT STATEMENTS FOR THE TABLES CAN YOU PLEASE ADD SOME INSERT STATEMENTS FOR A COMPANY SCHEMA SCRIPT. PLEASE ADN THANK YOU DROP TABLE dependent; DROP TABLE works_on; DROP TABLE project; DROP TABLE dept_locations; DROP TABLE department; DROP TABLE employee; CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary numeric(10,2), superssn char(9), dno numeric, primary key (ssn), foreign key (superssn) references employee(ssn) ); CREATE...

  • Based on the schemas given below, give the appropriate “SQL” and “Relational algebra” statements for the...

    Based on the schemas given below, give the appropriate “SQL” and “Relational algebra” statements for the given queries Marking scheme: 1 mark for each correct syntax for SQL and Relational Algebra Employee (fname, Iname, ssn, sex, salary, dno) Department (dname, dno, managersn, dlocation) Project (pname, pno, plocation, dno) a) Find out which department “Evelyn" is working in. b) Retrieve the names of all the projects which are located in “Isa Town". c) Count the number of employees who receive a...

  • Consider the relational database schema for a company below. EMPLOYEE/NAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN,...

    Consider the relational database schema for a company below. EMPLOYEE/NAME, SSN, BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNA) TA DEPARTMENT(DNAME, DNUMBER. MESSINS, MGRSTARTDATE) DEPT_LOCATIONS(DNUMBER. DLOCATION PROJECT(PNAME, PNUMBER. PLOCATION, DNLIM) WORKS_ONCESSN.PNG, HOURS) DEPENDENTESSN, DEPENDENT-NAME, SEX, BDATE, RELATIONSHIP) Write SQL statements for the following queries: a) List the names of those employees who work in the "Production" department (6 marks). b) Find the maximum salary, minimum salary, and the average salary among employees who work for the "Production department (6 marks). Count the...

  • Use the tables in the next page to answer the following questions in SQL. 1. Print...

    Use the tables in the next page to answer the following questions in SQL. 1. Print the names of employees who work in a project located in Houston. 2. Print the names of employees with no dependents. 3. Print the names of employees who are managers. 4. Print the names of employees who have more than one wife. 5. Print the names of employees who work in all the projects. EMPLOYEE Frame John Franklin Minit B T S K A...

  • (SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith') UNION (SELECT pnumber FROM...

    (SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith') UNION (SELECT pnumber FROM project, works_on, employee WHERE pnumber=pno AND essn=ssnAND lname='Smith') Can you draw the relation step by step , how to solve it ?! Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 3334455555 Ssn Fname Minit Lname John Franklin TWong 333445555 1955-12-08 638 Voss, Houston, TXM40000...

  • Write SQL Queries Given the following tables (7pts) Retrieve the names of employees and their project...

    Write SQL Queries Given the following tables (7pts) Retrieve the names of employees and their project name. If the employee never worked on a project, show the names only the name, not the project name. (7pts) Retrieve the names of employees who have worked on the same project at a different location. (7pts) Retrieve the names of employees who have worked on more than two different projects. (7pts) Retrieve the names of employees who manage more than two employees. CREATE...

  • Due date: November 6, 2018 (Tuesday) Problems: 1. Specify the following queries on the database schema...

    Due date: November 6, 2018 (Tuesday) Problems: 1. Specify the following queries on the database schema shown in Figure 3.6 using both the tuple relational calculus and the domain relational calculus. You don't need to show the result of each query if applied to the database of Figure 3.6. (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project (b) List the names of employees who have a dependent...

  • Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compar...

    Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compare with your solution to make sure I did it correctly. Thank you very much! LAB exercises 2 Write the Oracle DML query codes for the following questions and take the screen shot of the output. 1. Retrieve the name and address of all employees...

  • Problem 1 (25 points) Consider the following database schema: Employee (fname, Iname, ssn, address, salary, mgrssn,...

    Problem 1 (25 points) Consider the following database schema: Employee (fname, Iname, ssn, address, salary, mgrssn, dnumber) Department (dname, dnumber, mgrssn, mngrstartdate) Project (pname, pnumber, plocation, dnumber) Works_On (ssn, pnumber, hours_per_week) Dependent (ssn, dependent name, bdate, relationship) The above relations store information about a company. The meaning of most of the relations and attributes is straightforward. For example, the first relation stores information about employees. The mgrssn is the SSN of the manager (supervisor) of the given employee. A manager...

  • Search all employee who work total on all project less than 40 hrs from works_on table....

    Search all employee who work total on all project less than 40 hrs from works_on table. Please give me a query for this. Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Fname Minit Lname Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 333445555 5 FranklinT Wong 333445555 1955-12-08 638 Voss, Houston, TX M 40000 888665555 5 JZelaya 999887777 1968-01-19 3321 Castle, Spring, TX F 25000 9876543214 JenniferSWallace 9876543211941-06-20...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT