Biggest Single Number
Problem
MyNumbers(num). Return the largest value that appears exactly once, or NULL if none.
n=[(8,),(8,),(3,),(3,),(1,),(4,),(5,),(6,)]6SELECT MAX(num) AS num
FROM (SELECT num FROM MyNumbers GROUP BY num HAVING COUNT(*) = 1) t;
Explanation
We want the largest number that appears exactly once. The clean way is to first throw away every value that shows up more than once, and then take the maximum of what remains.
The inner query SELECT num FROM MyNumbers GROUP BY num HAVING COUNT(*) = 1 does the filtering. Grouping by num collapses identical values together, and HAVING COUNT(*) = 1 keeps only the groups that had a single row — the truly unique numbers.
The outer SELECT MAX(num) then picks the biggest of those uniques. A nice bonus: if there are no unique numbers at all, MAX over an empty set returns NULL, which is exactly what the problem asks for.
Example: for 8, 8, 3, 3, 1, 4, 5, 6, grouping gives counts 8→2, 3→2, 1→1, 4→1, 5→1, 6→1. The HAVING keeps {1, 4, 5, 6}, and MAX of those is 6.