Oracle DISTINCT Clause πΒΆ
Prerequisites: SELECT Statement
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!