Skip to main content

Oracle Set Operators πŸ•ΈοΈ

Mentor's Note: Set operators are like "Result Math". Instead of joining tables side-by-side, we take two complete query results and stack them, overlap them, or subtract one from the other. πŸ’‘


🌟 The Scenario: The App Merger πŸ“±β€‹

Your company has two separate apps: One for the Web and one for Mobile.

  • UNION: Get a list of ALL unique emails from both apps.
  • INTERSECT: Find users who use BOTH apps.
  • MINUS: Find users who use the Web app but have NOT downloaded the Mobile app.

πŸ’» 1. UNION & UNION ALL (The Stacker)​

  • UNION: Combines results and removes duplicates.
  • UNION ALL: Combines results and keeps duplicates (Faster!).
SELECT email FROM web_users
UNION
SELECT email FROM mobile_users;

πŸ’» 2. INTERSECT (The Overlap) πŸ€β€‹

Returns only rows that exist in both query results.

SELECT city FROM customers
INTERSECT
SELECT city FROM suppliers;

πŸ’» 3. MINUS (The Subtractor) βœ‚οΈβ€‹

Returns rows from the first query that are not present in the second.

SELECT product_id FROM inventory
MINUS
SELECT product_id FROM sales; -- "What hasn't sold?"

πŸ—οΈ Architect's Note: Performance & Rules πŸ›‘οΈβ€‹

  1. The "Union All" Rule: Always use UNION ALL instead of UNION if you know there are no duplicates. UNION forces an expensive "Sort Unique" operation.
  2. Column Rules:
    • Both queries must have the same number of columns.
    • The data types must be compatible.
    • Headers are taken from the first query.

πŸ“ˆ Learning Path​

πŸ“ Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
πŸ“ Address
2/66 Faram Street, Rustompura
Surat – 395002, Gujarat, India
πŸ“ž Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition β€” Areas We Serve in Surat

Adajanβ€’Althanβ€’Amroliβ€’Athwaβ€’Athwalinesβ€’Bhagalβ€’Bhatarβ€’Bhestanβ€’Canal Roadβ€’Chowkβ€’Citylightβ€’Dumasβ€’Gaurav Pathβ€’Ghod Dod Roadβ€’Haziraβ€’Jahangirpuraβ€’Kamrejβ€’Kapodraβ€’Katargamβ€’Limbayatβ€’Magdallaβ€’Majura Gateβ€’Mota Varachhaβ€’Nanpuraβ€’New Citylightβ€’Olpadβ€’Palβ€’Pandesaraβ€’Parle Pointβ€’Piplodβ€’Punaβ€’Randerβ€’Ring Roadβ€’Rustampuraβ€’Sachinβ€’Salabatpuraβ€’Sarthanaβ€’Sosyo Circleβ€’Udhnaβ€’Varachhaβ€’Ved Roadβ€’Vesuβ€’VIP Road
πŸ“ž Call SirπŸ’¬ WhatsApp Sir