Informatics Practices · Ch 1 — Querying and SQL Functions
Minus (-)
Minus (-)
The MINUS Operation (Set Difference)
The MINUS operation, written with the minus sign (−), answers a simple question: Which rows exist in the first table but not in the second? It is also called set difference. Figure 1.5 shows this as a Venn diagram — the crescent of one circle lying outside the other.
Using the same DANCE and MUSIC relations, suppose you want the list of students who are participating only in Music and not in Dance:
SELECT * FROM Music
MINUS
SELECT * FROM Dance;
The output — shown in Table 1.14 — gives the three students who are in the Music table but not in the Dance table: Mehak, Lavanya and Abhay. Notice that the table heading in the textbook reads "DANCE - MUSIC" — this is a minor labelling error in the original text; the operation correctly returns Music minus Dance.
How It Works
- The operation compares two tables (or result sets) that must have the same structure — same number of columns and compatible data types.
- It returns only those rows that appear in the first table and are absent from the second table.
- Duplicate rows are automatically removed from the result (just like in set theory).
The MINUS operation is not supported in MySQL (which is the database used in your CBSE practical exams). MySQL provides the EXCEPT operator in some versions, but for your syllabus, you should understand the concept of set difference using MINUS. In practice, you would achieve the same result using a LEFT JOIN with a WHERE clause checking for NULL in the second table.
Key Points to Remember
- MINUS is a set operation, not a join. It compares entire rows, not just key columns. …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your NCERT textbook's own diagram.
The figure is a Venn diagram with two overlapping circles, no surrounding rectangle. The left circle is labelled Music, the right circle is labelled Dance. The overlapping region in the middle — the intersection — is left unshaded. The entire portion of the Music circle that does not overlap with Dance is shaded. This shaded crescent shape represents the set difference Music Dance: all students who appear in Music but not in Dance. …
| SNo | Name | Class |
|---|---|---|
| 1 | Mehak | 8A |
| 3 | Lavanya | 7A |