Commit 8f27469
committed
feat(sql-set-ops): add explanation of SQL Set Operations
What
- Added documentation of SQL set operations that combine results of multiple queries:
- UNION → merges results of two queries, removing duplicates.
- UNION ALL → merges results, keeping duplicates.
- INTERSECT → returns rows common to both queries.
- EXCEPT / MINUS (DB-specific) → returns rows from first query not present in second.
- Explained syntax with simple two-table examples (e.g., students vs alumni).
- Highlighted rules: same number of columns, compatible data types.
Why
- Set operations are fundamental for advanced SQL querying when multiple datasets must be compared or merged.
- Developers often face scenarios like combining customers and leads, or finding overlapping records.
- Distinguishes set-based operations from joins (row vs set comparison).
How to use
- UNION: Merge active and inactive employee lists into one result set.
- UNION ALL: Combine product sales logs while keeping duplicate entries.
- INTERSECT: Find students who are also alumni.
- EXCEPT/MINUS: Identify customers who have not yet placed an order.
Real-life Applications
- Data warehousing: Merging historical and live datasets.
- Business intelligence: Finding overlaps or differences between customer segments.
- Compliance: Extracting records missing in one system compared to another.
Notes
- UNION removes duplicates automatically; use UNION ALL for performance if duplicates are acceptable.
- Column names in result set follow the first query.
- DBMS differences: MINUS in Oracle vs EXCEPT in SQL Server/PostgreSQL.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 7239773 commit 8f27469
File tree
4 files changed
+17
-21
lines changed- Section28JDBCusingSQLite/SQL (Aggregated Functions & Set Operations)/Set Operations SQL
4 files changed
+17
-21
lines changedLines changed: 8 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
14 | 11 | | |
| 12 | + | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | | - | |
29 | | - | |
| 26 | + | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
42 | | - | |
43 | | - | |
| 39 | + | |
44 | 40 | | |
45 | 41 | | |
46 | 42 | | |
| |||
53 | 49 | | |
54 | 50 | | |
55 | 51 | | |
56 | | - | |
57 | 52 | | |
| 53 | + | |
58 | 54 | | |
59 | 55 | | |
60 | 56 | | |
| |||
68 | 64 | | |
69 | 65 | | |
70 | 66 | | |
71 | | - | |
72 | | - | |
| 67 | + | |
73 | 68 | | |
74 | 69 | | |
75 | 70 | | |
| |||
90 | 85 | | |
91 | 86 | | |
92 | 87 | | |
93 | | - | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
0 commit comments