20bcs3023 Dbms Assign 1 Ques 1
20bcs3023 Dbms Assign 1 Ques 1
SEMESTER –3rd
SUBJECT: DBMS
Q1. Show the use of UNION and INTERSECT operator using relations.
SOL: Union
Union combines two different results obtained by a query into a single result in the form of
a table. However, the results should be similar if union is to be applied on them. Union
removes all duplicates, if any from the data and only displays distinct values. If duplicate
values are required in the resultant data, then UNION ALL is used.
An example of union is −
Select Student_Name from Art_Students
UNION
Select Student_Name from Dance_Students
.
Intersect :
The intersection operator gives the common data values between the two data sets that are
intersected. The two data sets that are intersected should be similar for the intersection operator
to work. Intersection also removes all duplicates before displaying the result.
describe Art_students;
describe Dance_students;
UNION
INTERSECT
DANCE_STUDENT TABLE
INTERSECT: This will display the names of the students in the table Art_Students and in
the table Dance_Students i.e all the students that have taken both art and dance classes .Those
are Anuj ,Kunal and Tushar in this example