Biggest Single Number
Task: 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.
Table: MyNumbers
| Column Name | Type |
|---|---|
| num | INT |
Input: MyNumbers table:
| num |
|---|
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
Output:
| num |
|---|
| 6 |
View Reference Solution & Explanation ▼
This solution uses the `GROUP BY` clause to aggregate results, a `HAVING` clause to filter the aggregated groups, and a subquery as a derived table or inline value.
SELECT MAX(num) AS num FROM (SELECT num FROM MyNumbers GROUP BY num HAVING COUNT(num) = 1);