Knowledge Guide
HomeDatabasesSQL Practice Problems

Biggest Single Number

Problem

Table: MyNumbers

+-------------+------+
| Column Name | Type |
+-------------+------+
| num         | int  |
+-------------+------+
This table may contain duplicates (In other words, there is no primary key for this table in SQL).
Each row of this table contains an integer.

Problem Definition

A single number is a number that appeared only once in the MyNumbers table.

Find the largest single number. If there is no single number, report null.

Example

Image
Image

Output

Image
Image

Try It YourSelf

java
-- TODO: Write your user queries here

Solution

We can solve this through a query that utilizes a subquery to identify numbers that appear more than once in the MyNumbers table by grouping them and applying a count condition. The main query then retrieves the maximum value from the table, excluding those numbers identified by the subquery.

The step-by-step process involves filtering out non-unique numbers and applying the MAX function to the remaining unique numbers, assigning the result the alias 'num'.

SELECT Max(num) AS num FROM MyNumbers WHERE num NOT IN (SELECT num FROM MyNumbers GROUP BY num HAVING Count(*) > 1;

Let's break down the query step by step:

Step 1: Subquery: Identifying Non-Unique Numbers

SELECT num FROM MyNumbers GROUP BY num HAVING Count(*) > 1;

The subquery is grouping the rows of the MyNumbers table by the num column.

The HAVING COUNT(*) > 1 condition filters the groups to include only those where the count of occurrences of each num is greater than 1.

Output After Step 1:

+-----+ | num | +-----+ | 3 | | 8 | +-----+

Step 2: Main Query: Selecting Maximum Value Among Unique Numbers

SELECT Max(num) AS num FROM MyNumbers WHERE num NOT IN (SELECT num FROM MyNumbers GROUP BY num HAVING Count(*) > 1);

The main query uses the MAX(num) function to find the maximum value from the MyNumbers table.

The WHERE clause filters out rows where the num value is in the set of non-unique numbers identified by the subquery.

Final Output:

+-----+ | num | +-----+ | 6 | +-----+
🤖 Don't fully get this? Learn it with Claude

Stuck on Biggest Single Number? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Biggest Single Number** (Databases) and want to truly understand it. Explain Biggest Single Number from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Biggest Single Number** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Biggest Single Number** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Biggest Single Number** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes