- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Relational Set Operators in DBMS
DBMS supports relational set operators as well. The major relational set operators are union, intersection and set difference. All of these can be implemented in DBMS using different queries.
The relational set operators in detail using given example are as follows as follows −
Student_Number | Student_Name | Student_Marks |
1 | John | 95 |
2 | Mary | 80 |
3 | Damon | 57 |
Student_Number | Student_Name | Student_Marks |
2 | Mary | 50 |
3 | Damon | 98 |
6 | Matt | 45 |
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
This will display the names of all the students in the table Art_Students and Dance_Students i.e John, Mary, Damon and Matt.
Intersection
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.
An example of intersection is −
Select Student_Name from Art_Students INTERSECT Select Student_Name from Dance_Students
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 Mary and Damon in this example.
Set difference
The set difference operators takes the two sets and returns the values that are in the first set but not the second set.
An example of set difference is −
Select Student_Name from Art_Students MINUS Select Student_Name from Dance_Students
This will display the names of all the students in table Art_Students but not in table Dance_Students i.e the students who are taking art classes but not dance classes.
That is John in this example.
- Related Articles
- Explain set operators in DBMS
- Relational Operators in C++
- Java Relational Operators
- Basic Operators in Relational Algebra
- Relational Operators in Dart Programming
- Explain the Relational Model in DBMS?
- Explain the relational algebra in DBMS?
- Relational and Logical Operators in C
- What are relational operators in C#?
- Relational and comparison operators in C++
- C++ Relational and Equality Operators
- Extended Operators in Relational Algebra in C++
- Explain project operation in relational algebra (DBMS)?
- Explain rename operation in relational algebra (DBMS)?
- Explain union operation in relational algebra (DBMS)?
