Find the Largest Single Number
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Description
You are given a table MyNumbers that contains integers, possibly with duplicates. A single number is defined as a number that appears exactly once in the table. Write a SQL query to find the largest single number. If there are no single numbers, return null.
Database Schema
MyNumbers
| Column Name | Example Value |
|---|---|
| num | 8 |
Example
MyNumbers
| num |
|---|
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
Output
| num |
|---|
| 6 |
Explanation:
Numbers appearing exactly once: 1, 4, 5, 6. The largest among them is 6.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
SQL Editor
Loading...
MyNumbers
| num |
|---|
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
Output
| num |
|---|
| 6 |