# Refer to: https://stackoverflow.com/questions/17250243/how-to-return-null-when-result-is-empty select( select num from number group by num having count(*) = 1 order by num desc limit 1 ) as num;
select max(a.num) as num from (select num from number group by num having count(*)=1) as a
Actually the first solution is much faster than the solution above. They are different. The second one uses a derived table while the first one does not. the first one beats about 85% but the second one only beats about 45%. BTW, it is a very clever idea to transform empty values to NULL using the first solution.