Class 12 SQLSQLSQLSQLSQL
Class 12 SQLSQLSQLSQLSQL
Computer Science(083)
Topic :Queries Based on two tables
ASSIGNMENT
Section A : MCQ Questions
1. Consider a relation/table EMP & DEPT and give the correct answer of following :
Relation EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 1980-12-17 800.00 NULL 20
7499 ALLEN SALESMAN 7698 1981-02-20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981-02-22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981-04-02 2975.00 NULL 20
7654 MARTIN SALESMAN 7698 1981-09-28 1250.00 1400.0 30
7698 BLAKE MANAGER 7839 1981-05-01 2850.00 NULL 30
7782 CLARK MANAGER 7839 1981-06-09 2450.00 NULL 10
7788 SCOTT ANALYST 7566 1982-12-09 3000.00 NULL 20
7839 KING PRESIDENT NULL 1981-11-17 5000.00 NULL 10
7844 TURNE SALESMAN 7698 1981-09-08 1500.00 0.00 30
7876 ADAMS CLERK 7788 1983-01-12 1100.00 NULL 20
7900 JAMES CLERK 7698 1981-12-03 950.00 NULL 30
7902 FORD ANALYST 7566 1981-12-03 3000.00 NULL 20
7934 MILLER CLERK 7782 1982-01-23 1300.00 NULL 10
Relation: DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
19. Using …………. all rows from the second table will be returned whether there are matches in the
first table or not.
(a) LEFT JOIN (b) RIGHT JOIN (c) EQUI JOIN (d) CROSS JOIN
20. To display the name of employees who are getting more salary than the maximum salary of clerks.
(a) SELECT ENAME FROM EMP WHERE
SAL >(SELECT MAX(SAL) FROM EMP WHERE JOB=’CLERK’);
(b) SELECT ENAME , MAX(SAL) FROM EMP WHERE JOB=’CLERK’;
(c) SELECT ENAME FROM EMP WHERE SAL >MAX(SAL);
(d) NONE
21. Scalar functions are also known as :
(a) Single row function (b) Multiple row functions
(c) Group functions (d) None
Section B : Queries
1. Consider the following tables : Employee and Department:
Table: Employee
ECode LastName FirstName DepName
101 Sharma Amit Sales
102 Arora Shiv Personnel
103 Lakshmi KS Accounts
104 Rajlani Shivika Accounts
105 Thakral Satvik Sales
Write SQL statements(a-k) to do the following:
a. Display the last names and first names of all employees.
b. Display the Department names of all employees, without duplicates.
c. Display all the details of employees whose last name is having “L”.
d. Display all the details of employees whose last name is “Rajlani” or “Sharma”.
e. Display the codes and first names of all the employees of “Accounts” department.
Table: Department
DepCode DepName Budget ECode
D101 Sales 200000 101
D102 Personnel 150000 102
D104 Accounts 300000 103
D103 Sales 200000 104
f. Display ECode , Firstname , department name of departments with budget above
180000.
g. Display all the details of employees whose Last name begins with “S” and belongs to
Sales Department.
j. Add a new row with appropriate data values for ECode 105 in Department table.
k. An employee Shivalik Rajlani has left his job . Do the needful by removing his details
from the tables.
l. Show the Cartesian product of both tables.
m. What will be the degree and cardinality of both tables now.
2. Consider the tables given below. Table workshop is created before the workshops are organized.
Table “WrapUp” is created after the workshops to summarize about the actual number of
participants who attended the workshops and the highest designation amongst all the participants
who attended the workshops. Consider the tables given below.
Table : Workshop
WorkshopId Title Num_Speakers Number_Invites
551 Time Management 3 50
552 App Development 1 40
553 Development & Planning 2 20
554 Marketing Strategies 2 25
Table : WrapUP
WorkshopId ActualAttendees HighestAttendee
551 39 Associate Director
552 32 CEO
553 18 Sr. Executive
554 20 Sales Manager
** ActualAttendees column stores : Actual number of Attendees.
**HighestAttendee column stores : highest designation amongst participants.
a) Name the Primary keys in both the tables.