Module 5 Assignment - SQL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3
At a glance
Powered by AI
The key takeaways are performing SQL operations like order by, union, intersect, and except on sample employee and order datasets.

The SQL operations performed on the employee tables were creating two tables with sample data and then applying union, intersect, and except operators on the tables.

The result of applying the union operator on the two employee tables was combining the rows from both tables and removing duplicate rows.

Module-5 Assignment

Problem Statement:
You have successfully cleared your 4th semester. In the 5th semester you will work with group by, having
by clauses and set operators

Tasks to be done:

1. Arrange the ‘Orders’ dataset in decreasing order of amount


2. Create a table with name ‘Employee_details1’ and comprising of these columns – ‘Emp_id’,
‘Emp_name’, ‘Emp_salary’. Create another table with name ‘Employee_details2’, which
comprises of same columns as first table.
3. Apply the union operator on these two tables
4. Apply the intersect operator on these two tables
5. Apply the except operator on these two tables

Solutions

1.
SELECT * FROM orders
ORDER BY amount DESC

RESULT

Order_id order_date amount customer_id


1004 2021-10-18 200 4
1002 2021-10-16 150 2
1003 2021-10-17 100 3
1001 2021-10-15 100 1

2.

CREATE TABLE Employee_details1 (


Emp_id INT,"Emp_name" VARCHAR (20), Emp_salary INT
)

/2

ANITA BALAKRISHNAN EMAIL annkallid@gmail.com MODULE 5 ASSIGNMENT - SQL


-2-

INSERT INTO Employee_details1


VALUES
(1, 'John', 10000),
(2, 'James', 15000),
(3, 'Ann', 25000),
(4, 'Sara', 20000),
(5, 'Laura', 35000)

CREATE TABLE Employee_details2


(Emp_id INT,"Emp_name" VARCHAR (20), Emp_salary INT)

INSERT INTO Employee_details2


VALUES
(1, 'Jimmy', 40000),
(2, 'James', 15000),
(3, 'Ann', 25000),
(4, 'Susy', 30000),
(5, 'Lennie', 35000)

3.

SELECT * FROM Employee_details1


UNION
SELECT * FROM Employee_details2

RESULT

Emp_id Emp_name Emp_salary


1 Jimmy 40000
1 John 10000
2 James 15000
3 Ann 25000
4 Sara 20000
4 Susy 30000
5 Laura 35000
5 Lennie 35000

4.
SELECT * FROM Employee_details1
INTERSECT
SELECT * FROM Employee_details2

RESULT

Emp_id Emp_name Emp_salary


2 James 15000
3 Ann 25000

/3

ANITA BALAKRISHNAN EMAIL annkallid@gmail.com MODULE 5 ASSIGNMENT - SQL


-3-

5.

SELECT * FROM Employee_details1


EXCEPT
SELECT * FROM Employee_details2

RESULT

Emp_id Emp_name Emp_salary


1 John 10000
4 Sara 20000
5 Laura 35000

ANITA BALAKRISHNAN EMAIL annkallid@gmail.com MODULE 5 ASSIGNMENT - SQL

You might also like