Wednesday, September 16, 2026
Home Academic SET operations in SQL

SET operations in SQL

Set operations combines the results of two independent SQL queries. There are three set operations in SQL 

1.Union

2. Intersect

3. Except

These set operations operate on relations and are based on the general principles of mathematical set theory that you’ve probably covered in school level math. 

One thing to not forgot is, each of these operations automatically eliminates duplicates in the result. In order to retain all the duplicates, one can use the corresponding multiset versions of basic set operations union all, intersect all and except all.

Suppose a tuple/row occurs m times in a relation named r and n times in relation named s then it occurs

m  + n times in r union all s

min(m,n) times in r intersect all s

max(0, m – n) times in r except all s.

Some example queries are shown in image below:

The relation schemes for all the examples used above are:

Branch(bname, bcity, assets)

Customer(cname, street, ccity)

Depositor(cname, account#)

Account(bname, account#, balance)

Loan(bname, loan#, amount)

Borrower(cname, loan#)

datasagarhttp://www.DataSagar.com
Sagar is multidisciplinary technologist, educator, and entrepreneur based in Nepal. As the founder of Illionso Technologies and Kashi Garden Resort, he operates at the intersection of web architecture, data intelligence, innovation, and digital transformation. From building digital solutions to scaling real-world concepts, his mission is to share knowledge alongside merge emerging as well as disruptive technologies with transformative offline experiences.
RELATED ARTICLES

Meta Muse AI Agent Everything You Need to Know About Features and Privacy

Discover everything about Meta Muse, the new personal AI agent designed to execute goals 24/7. Explore its features, Secure Virtual Machine privacy, token pricing, and the future of autonomous AI.

Nepal Government Approves Software Development Center to Hire 93 IT Specialists – Gov Tech Updates

Nepal is taking a massive step forward in government technology. The administration has formally advanced plans...

1 COMMENT

Most Popular