CBSE Class 12 Informatics Practices
Question 65 of 91
JOINS and SET Operations — Question 1
Back to all questions 1
Question In a Database, there are two tables given below :
Table : EMPLOYEE
| EMPLOYEEID | NAME | SALES | JOBID |
|---|---|---|---|
| E1 | SUMIT SINHA | 1100000 | 102 |
| E2 | VIJAY SINGH TOMAR | 1300000 | 101 |
| E3 | AJAY RAJPAL | 1400000 | 103 |
| E4 | MOHIT RAMNANI | 1250000 | 102 |
| E5 | SHAILJA SINGH | 1450000 | 103 |
Table : JOB
| JOBID | JOBTITLE | SALARY |
|---|---|---|
| 101 | President | 200000 |
| 102 | Vice President | 125000 |
| 103 | Administration Assistant | 80000 |
| 104 | Accounting Manager | 70000 |
| 105 | Accountant | 65000 |
| 106 | Sales Manager | 80000 |
Write SQL Queries for the following :
To display employee ids, names of employees, job ids with corresponding job titles.
To display names of employees, sales and corresponding job titles who have achieved sales more than 1300000.
To display names and corresponding job titles of those employees who have 'SINGH' (anywhere) in their names.
Identify foreign key in the table EMPLOYEE.
Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table 'EMPLOYEE'.
1.
SELECT EMPLOYEE.EMPLOYEEID, EMPLOYEE.NAME, EMPLOYEE.JOBID, JOB.JOBTITLE
FROM EMPLOYEE, JOB
WHERE EMPLOYEE.JOBID = JOB.JOBID;+------------+-------------------+-------+--------------------------+
| EMPLOYEEID | NAME | JOBID | JOBTITLE |
+------------+-------------------+-------+--------------------------+
| E1 | SUMIT SINHA | 102 | VICE PRESIDENT |
| E2 | VIJAY SINGH TOMAR | 101 | PRESIDENT |
| E3 | AJAY RAJPAL | 103 | ADMINISTARTION ASSISTANT |
| E4 | MOHIT RAMNANI | 102 | VICE PRESIDENT |
| E5 | SHAILJA SINGH | 103 | ADMINISTARTION ASSISTANT |
+------------+-------------------+-------+--------------------------+
2.
SELECT EMPLOYEE.NAME, EMPLOYEE.SALES, JOB.JOBTITLE
FROM EMPLOYEE, JOB
WHERE EMPLOYEE.JOBID = JOB.JOBID
AND EMPLOYEE.SALES > 1300000;+---------------+---------+--------------------------+
| NAME | SALES | JOBTITLE |
+---------------+---------+--------------------------+
| AJAY RAJPAL | 1400000 | ADMINISTARTION ASSISTANT |
| SHAILJA SINGH | 1450000 | ADMINISTARTION ASSISTANT |
+---------------+---------+--------------------------+
3.
SELECT EMPLOYEE.NAME, JOB.JOBTITLE
FROM EMPLOYEE, JOB
WHERE EMPLOYEE.JOBID = JOB.JOBID
AND EMPLOYEE.NAME LIKE '%SINGH%';+-------------------+--------------------------+
| NAME | JOBTITLE |
+-------------------+--------------------------+
| VIJAY SINGH TOMAR | PRESIDENT |
| SHAILJA SINGH | ADMINISTARTION ASSISTANT |
+-------------------+--------------------------+
4. In the given tables, EMPLOYEE and JOB, the JOBID column in the EMPLOYEE table is a foreign key referencing the JOBID column in the JOB table.
5.
UPDATE EMPLOYEE
SET JOBID = 104
WHERE EMPLOYEEID = 'E4';SELECT * FROM EMPLOYEE ;+------------+-------------------+---------+-------+
| EMPLOYEEID | NAME | SALES | JOBID |
+------------+-------------------+---------+-------+
| E1 | SUMIT AINHA | 1100000 | 102 |
| E2 | VIJAY SINGH TOMAR | 1300000 | 101 |
| E3 | AJAY RAJPAL | 1400000 | 103 |
| E4 | MOHIT RAMNANI | 1250000 | 104 |
| E5 | SHAILJA SINGH | 1450000 | 103 |
+------------+-------------------+---------+-------+