Grokking SQL for Tech Interviews
Vote

0% completed

4. Biggest Single Number

Problem

Table: MyNumbers

+-------------+------+
| Column Name | Type |
+-------------+------+
| num         | int  |
+-------------+------+
This table may contain duplicates (In other words, there is no primary key for this table in SQL).
Each row of this table contains an integer.

Problem Definition

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.

Example

Output

Try It YourSelf

.....

.....

.....

Like the course? Get enrolled and start learning!
Christopher Guy Slater

Christopher Guy Slater

· 9 days ago

-- another way SELECT   num FROM MyNumbers GROUP BY num HAVING COUNT(*) = 1 ORDER BY num DESC LIMIT 1;
Sourav Singh

Sourav Singh

· 2 months ago

-- TODO: Write your user queries here SELECT MAX(single_number) AS num FROM ( SELECT num as single_number FROM MyNumbers GROUP BY num HAVING COUNT(num) = 1 ) AS filtertable;

Reading Progress

0%