Oracle DISTINCT Clause 💎¶
Mentor's Note: Your database might have 1,000 employees, but maybe they only live in 5 different cities.
DISTINCThelps you see those unique values without the repetition. 💡
🌟 The Scenario: The City Census 📍¶
- Goal: Find out which cities our company operates in.
- Problem: If 100 people live in Surat, you don't want to see "Surat" 100 times.
- Action: You use
DISTINCTto get a clean, unique list.
💻 1. Syntax & Examples¶
Example: Unique Job Titles¶
🏗️ Architect's Note: The Unique Sort 🛡️¶
When you run DISTINCT, Oracle internally performs a SORT UNIQUE or HASH UNIQUE operation. This means the database has to scan and compare every row to find duplicates.
- Pro Tip: If you know a table only has unique values (like a Primary Key column), using DISTINCT is a waste of CPU power!