Skip to content

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. DISTINCT helps 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 DISTINCT to get a clean, unique list.

πŸ’» 1. Syntax & ExamplesΒΆ

SELECT DISTINCT column_name FROM table_name;

Example: Unique Job TitlesΒΆ

SELECT DISTINCT job_id FROM employees;

πŸ—οΈ 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!


πŸ“ˆ Learning PathΒΆ