0% found this document useful (0 votes)
56 views

Assignment 4 Solution

1. The document describes creating two tables, EMP_E1 and EMP_E2, with employee data like ID, name, salary, and department. It inserts sample data into the tables. 2. It provides 4 queries: a) displays all records from both tables with duplicates, b) displays all records from both tables uniquely, c) displays employees in the HR department from both tables, and d) displays employees with salary over 20k from both tables.

Uploaded by

Alankar dhakate
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Assignment 4 Solution

1. The document describes creating two tables, EMP_E1 and EMP_E2, with employee data like ID, name, salary, and department. It inserts sample data into the tables. 2. It provides 4 queries: a) displays all records from both tables with duplicates, b) displays all records from both tables uniquely, c) displays employees in the HR department from both tables, and d) displays employees with salary over 20k from both tables.

Uploaded by

Alankar dhakate
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment 4

1. Create below tables,

EMP_E1

ID Name Salary Dept


1 A 10000 IT
2 B 20000 IT
3 C 30000 HR
4 D 20000 HR
5 E 60000 HR
6 F 70000 FIN
7 G 40000 FIN
8 H 20000 ADM

CREATE TABLE EMP_E1(


ID NUMBER,
NAME VARCHAR2(3),
SALARY NUMBER,
DEPT VARCHAR2(3)
);

INSERT ALL
INTO EMP_E1 values(1, 'A', 10000, 'IT')
INTO EMP_E1 values(2, 'B', 20000, 'IT')
INTO EMP_E1 values(3, 'C', 30000, 'HR')
INTO EMP_E1 values(4, 'D', 20000, 'HR')
INTO EMP_E1 values(5, 'E', 60000, 'HR')
INTO EMP_E1 values(6, 'F', 70000, 'FIN')
INTO EMP_E1 values(7, 'G', 40000, 'FIN')
INTO EMP_E1 values(8, 'H', 20000, 'ADM')
SELECT * FROM DUAL;
EMP_E2

ID Name Salary Dept


101 x 90000 IT
102 y 30000 IT
103 z 32000 HR
104 p 11000 HR
105 q 10000 HR
6 f 70000 FIN
7 g 40000 FIN
8 h 20000 ADM

CREATE TABLE EMP_E2(


ID NUMBER,
NAME VARCHAR2(3),
SALARY NUMBER,
DEPT VARCHAR2(3));

INSERT ALL
INTO EMP_E2 values(101, 'X', 90000 , 'IT')
INTO EMP_E2 values(102, 'Y', 30000 , 'IT')
INTO EMP_E2 values(103, 'Z', 32000 , 'HR')
INTO EMP_E2 values(104, 'P', 11000 , 'HR')
INTO EMP_E2 values(105, 'Q', 10000 , 'HR')
INTO EMP_E2 values(6, 'F', 70000 , 'FIN')
INTO EMP_E2 values(7, 'G', 40000 , 'FIN')
INTO EMP_E2 values(8, 'H', 20000 , 'ADM')
SELECT * FROM DUAL;
a. Write a query to display all the records from EMP_E1 and EMP_E2.

SELECT * FROM EMP_E1


UNION ALL
SELECT * FROM EMP_E2;
b. Write a query to display all records from EMP_E1 and EMP_E2 records
should be unique.

SELECT * FROM EMP_E1


UNION
SELECT * FROM EMP_E2;
c. Write a query to select those employees who are working in HR
department from EMP_E1 and EMP_E2 table.

SELECT * FROM EMP_E1


WHERE DEPT='HR'
UNION
SELECT * FROM EMP_E2
WHERE DEPT='HR';
d. Write a query to select those employees who is having salary more then
20K. from both the tables.

SELECT * FROM EMP_E1


WHERE SALARY>20000
UNION
SELECT * FROM EMP_E2
WHERE SALARY>20000;

You might also like