Sitemap
2 min readDec 5, 2025

--

๐ŸŽฏ๐’๐๐‹ ๐’๐ž๐ซ๐ข๐ž๐ฌ | ๐„๐ฉ. ๐Ÿ• โ€” ๐†๐‘๐Ž๐”๐ ๐๐˜ & ๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“: ๐”๐ง๐๐ž๐ซ๐ฌ๐ญ๐š๐ง๐๐ข๐ง๐  ๐”๐ง๐ข๐ช๐ฎ๐ž๐ง๐ž๐ฌ๐ฌ ๐ข๐ง ๐ƒ๐š๐ญ๐š

๐–๐ก๐ฒ ๐œ๐จ๐ฎ๐ง๐ญ๐ข๐ง๐  ๐จ๐ง๐œ๐ž ๐ฏ๐ฌ ๐ฆ๐š๐ง๐ฒ ๐ญ๐ข๐ฆ๐ž๐ฌ ๐ฆ๐š๐ญ๐ญ๐ž๐ซ๐ฌ ๐ฆ๐จ๐ซ๐ž ๐ญ๐ก๐š๐ง ๐ฒ๐จ๐ฎ ๐ญ๐ก๐ข๐ง๐ค

๐Ÿง  ๐‡๐จ๐จ๐ค:
Imagine youโ€™re analyzing the ๐Ž๐ฅ๐ฒ๐ฆ๐ฉ๐ข๐œ ๐†๐š๐ฆ๐ž๐ฌ dataset.
You want to find ๐ฐ๐ก๐ข๐œ๐ก ๐Ž๐ฅ๐ฒ๐ฆ๐ฉ๐ข๐œ ๐ž๐๐ข๐ญ๐ข๐จ๐ง ๐ก๐š๐ ๐ญ๐ก๐ž ๐ก๐ข๐ ๐ก๐ž๐ฌ๐ญ ๐ง๐ฎ๐ฆ๐›๐ž๐ซ ๐จ๐Ÿ ๐ฎ๐ง๐ข๐ช๐ฎ๐ž ๐š๐ญ๐ก๐ฅ๐ž๐ญ๐ž๐ฌ.
If you used ๐‚๐Ž๐”๐๐“(*), youโ€™d count every row (including duplicates).
But what if the same athlete appears more than once in different events?
Thatโ€™s where understanding uniqueness in SQL becomes critical.

๐Ÿ’ก ๐‚๐จ๐ง๐œ๐ž๐ฉ๐ญ ๐๐ซ๐ž๐š๐ค๐๐จ๐ฐ๐ง:
1๏ธโƒฃ ๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“ helps you capture one-of-each: unique values or combinations.
2๏ธโƒฃ ๐†๐‘๐Ž๐”๐ ๐๐˜ helps you aggregate by categories: one row per group, summarized values.
3๏ธโƒฃ When you combine them: you get metrics like โ€œnumber of unique athletes per Olympic editionโ€.

๐”๐ฌ๐ž ๐œ๐š๐ฌ๐ž ๐ซ๐ฎ๐ฅ๐ž ๐จ๐Ÿ ๐ญ๐ก๐ฎ๐ฆ๐›:
โžก๏ธ Use ๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“ when you care about how many unique entities.
โžก๏ธ Use ๐†๐‘๐Ž๐”๐ ๐๐˜ when you care about how many / how much per category.

๐Ÿงฉ ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž ๐Ÿ๐ซ๐จ๐ฆ ๐’๐ญ๐ซ๐š๐ญ๐š๐’๐œ๐ซ๐š๐ญ๐œ๐ก:
๐Ÿ”— ๐‹๐š๐ซ๐ ๐ž๐ฌ๐ญ ๐Ž๐ฅ๐ฒ๐ฆ๐ฉ๐ข๐œ๐ฌ: https://lnkd.in/e_tZYS6W

๐๐ฎ๐ฌ๐ข๐ง๐ž๐ฌ๐ฌ ๐ช๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง:
โ€œFind the Olympics edition (year + season) with the highest number of unique athletes.โ€

Get Somyaguptaโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

๐’๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง ๐ฌ๐ค๐ž๐ญ๐œ๐ก:

SELECT
games,
COUNT(DISTINCT id) AS athlete_count
FROM olympics_athletes_events
GROUP BY games
ORDER BY athlete_count DESC
LIMIT 1;

โžก๏ธ ๐‚๐Ž๐”๐๐“(๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“ ๐ข๐) ensures each athlete is counted once per โ€œgamesโ€.
โžก๏ธ ๐†๐‘๐Ž๐”๐ ๐๐˜ games allows us to summarise by each edition.
โžก๏ธ ๐Ž๐‘๐ƒ๐„๐‘ ๐๐˜ โ€ฆ DESC picks the edition with most unique athletes.

๐Ÿ” ๐–๐ก๐ฒ ๐ญ๐ก๐ข๐ฌ ๐ฆ๐š๐ญ๐ญ๐ž๐ซ๐ฌ:
By properly combining ๐ƒ๐ˆ๐’๐“๐ˆ๐๐‚๐“ and ๐†๐‘๐Ž๐”๐ ๐๐˜, you avoid double-counting and get correct metrics.

๐…๐จ๐ซ ๐ž๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž:
1. How many distinct customers bought each category?
2. Which quarter had the most unique new users?
3. Which product was launched by most distinct companies?
These are common real-world questions โ€” and if you answer them incorrectly, youโ€™ll mislead business decisions.

๐Ÿงฉ ๐“๐ซ๐ฒ ๐ญ๐ก๐ž๐ฌ๐ž ๐ฉ๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:
1๏ธโƒฃ Marketing Campaign Success โ€” Advanced โ†’ segment performance, unique users per campaign.
2๏ธโƒฃ Actor Rating Difference Analysis โ†’ unique actors, movies, ratings across time.

Have you ever faced a metric that seemed โ€œsimpleโ€ but produced wrong results because of duplicates or missing grouping?
Share your story โ€” letโ€™s learn from each other. ๐Ÿ‘‡

๐Ÿš€ ๐‚๐จ๐ฆ๐ข๐ง๐  ๐๐ž๐ฑ๐ญ:
๐’๐๐‹ ๐’๐ž๐ซ๐ข๐ž๐ฌ | ๐„๐ฉ. ๐Ÿ– โ€” ๐‡๐€๐•๐ˆ๐๐†: ๐…๐ข๐ฅ๐ญ๐ž๐ซ๐ข๐ง๐  ๐†๐ซ๐จ๐ฎ๐ฉ๐ฌ, ๐๐จ๐ญ ๐‘๐จ๐ฐ๐ฌ

--

--