0% found this document useful (0 votes)
53 views5 pages

20bcs3023 Dbms Assign 1 Ques 1

The document is an assignment response that demonstrates the use of UNION and INTERSECT operators on relations. It shows: 1) UNION combines results from two queries and removes duplicates, while UNION ALL preserves duplicates. INTERSECT returns only common data values between relations. 2) Tables for art and dance students are created with sample data. 3) UNION and INTERSECT examples are given, showing they return all student names or just names common to both tables, respectively.

Uploaded by

Anuj Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

20bcs3023 Dbms Assign 1 Ques 1

The document is an assignment response that demonstrates the use of UNION and INTERSECT operators on relations. It shows: 1) UNION combines results from two queries and removes duplicates, while UNION ALL preserves duplicates. INTERSECT returns only common data values between relations. 2) Tables for art and dance students are created with sample data. 3) UNION and INTERSECT examples are given, showing they return all student names or just names common to both tables, respectively.

Uploaded by

Anuj Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assisgnment-1(Question:1)

STUDENT’S NAME – ANUJ SONI

STUDENT’S UID –20BCS3023

CLASS AND GROUP –20BCS15_A

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.

SUBJECT NAME- DATA STRUCTURE LAB


SUBJECT CODE-CSP-212
An example of intersection is −
Select Student_Name from Art_Students
INTERSECT
Select Student_Name from Dance_Students
CODE :
------------------FIRST TABLE FOR ART STUDENTS------------------------

create table Art_students(student_id number,student_name varchar(10),student_location varchar(30));

describe Art_students;

insert into Art_students values(6,'Anuj','delhi');

insert into Art_students values(5,'Utpal','patna');

insert into Art_students values(9,'Tushar','jhansi');

insert into Art_students values(7,'Radhe','agra');

insert into Art_students values(8,'Kunal','lucknow');

select *from Art_students;

-----------------SECOND TABLE FOR DANCE STUDENT------------------------

create table Dance_students(student_id number,student_name varchar(10),student_location varchar(30));

describe Dance_students;

insert into Dance_students values(6,'Anuj','delhi');

insert into Dance_students values(1,'gaurav','goa');

insert into Dance_students values(9,'Tushar','jhansi');

insert into Dance_students values(2,'prateek','mumbai');

insert into Dance_students values(8,'Kunal','lucknow');

select * from Dance_students;

-------EXAMPLE HOW TO USE UNION OPERATOR---------

Select student_name from Art_Students

UNION

Select student_name from Dance_Students;

-------EXAMPLE HOW TO USE INTERSECT OPERATOR--------

Select student_name from Art_Students

INTERSECT

Select student_name from Dance_Students;

SUBJECT NAME- DATA STRUCTURE LAB


SUBJECT CODE-CSP-212
Output:
ART_STUDENT TABLE

DANCE_STUDENT TABLE

SUBJECT NAME- DATA STRUCTURE LAB


SUBJECT CODE-CSP-212
UNION: This will display the names of all the students in the table Art_Students and
Dance_Students i.e Anuj,Kunal.Radhe,Tushar,Utpal,Gaurav and Prateek.

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

SUBJECT NAME- DATA STRUCTURE LAB


SUBJECT CODE-CSP-212
SUBJECT NAME- DATA STRUCTURE LAB
SUBJECT CODE-CSP-212

You might also like