QA
Beginner LevelSQL & MySQL

How does SELECT DISTINCT eliminate duplicate result rows?

❓ Interview Prompt: Explain `SELECT DISTINCT`, multi-column uniqueness evaluation, performance implications, and alternatives using `GROUP BY`.

The 'SELECT DISTINCT' clause removes duplicate rows from the query result set:

Mechanics:

•
Operates across ALL projected columns in the 'SELECT' clause to evaluate unique row combinations.
•
Requires the database engine to perform a sort or hash operation on the intermediate result set to collapse matching duplicate rows.

Code Implementation Example

sql
-- Retrieve unique list of countries from customer profiles
SELECT DISTINCT country, city
FROM customers
WHERE status = 'ACTIVE'
ORDER BY country, city;
💡Selecting unique country and city combinations using DISTINCT.
🎯 Interview Key Takeaway

Use SELECT DISTINCT to filter duplicate rows, but be mindful of sorting overhead on large datasets.

#SQL#DISTINCT#Deduplication#Beginner
Back to all SQL & MySQL Questions→

More SQL & MySQL Interview Questions

Beginner LevelSQL & MySQL

How do B-Tree Indexes work in SQL/MySQL and how do you optimize slow queries using EXPLAIN?

Beginner LevelSQL & MySQL

How do SELECT, WHERE, ORDER BY, and LIMIT clauses filter relational datasets?

Beginner LevelSQL & MySQL

What are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?