Description
Write a SQL query to find the largest number that appears only once. Return the number or NULL if none exists.
Table:
my_numbers| Column | Type |
|---|---|
| num | INT |
Examples
Input:
CREATE TABLE my_numbers (num INT); INSERT INTO my_numbers VALUES (8), (8), (3), (3), (1), (4), (5), (6);Output:
6Explanation:
Numbers 8 and 3 appear twice, so they're not unique. Numbers 1, 4, 5, 6 each appear once. The largest among these unique numbers is 6.
Input:
CREATE TABLE my_numbers (num INT); INSERT INTO my_numbers VALUES (10), (20), (20), (30), (30), (40), (40);Output:
10Explanation:
Only the number 10 appears exactly once in the table, while all other numbers (20, 30, 40) appear twice. Therefore, 10 is the largest (and only) single number.
Input:
CREATE TABLE my_numbers (num INT); INSERT INTO my_numbers VALUES (7), (7), (9), (9), (2), (2);Output:
NULLExplanation:
Every number in the table appears exactly twice: 7 appears twice, 9 appears twice, and 2 appears twice. Since there are no numbers that appear only once (no unique numbers), the query returns NULL.
Constraints
- •
Handle case where no unique number