I want to select the country with the highest population. This is my query:

```
SELECT continent, name, population FROM country HAVING population = MAX(population);

```

Somehow it returns 0 rows.

If i use a nested query it works:

```
SELECT continent, name, population FROM country WHERE population = (SELECT MAX(population) FROM country);

```

So my question is: What is wrong with the first query?

PS: You can download the database here:
<http://dev.mysql.com/doc/index-other.html>

---

Alright i think finally i figured out the whole process. Here how it works and why the alternative suggestions/solutions didn't work:

(First of all, as "Dan Bracuk" said in his answer, we have to combine GROUP BY with HAVING and add the aggregate function at the begininng in SELECT statement)

So let's go step by step and try this:

```
SELECT continent, name, population, MAX(population) FROM country;

```

This yields us the first row appended MAX(pop) at the end:   

**"North America", "Aruba", "103000", "1277558000"**

So MAX(population) is just one entry so it restricts the row number to 1 and because i added the continent, name, population columns, mysql just selects the first row from the table.

So if i now write down:

```
SELECT continent, name, population, MAX(population) FROM country HAVING population = MAX(population);

```

I get 0 rows, because 103000 is not equal to 1277558000.

If i use:

```
SELECT continent, name, population, MAX(population) FROM country GROUP BY name;

```

for instance, i get a list of all countries where on each row MAX(population) = population.

So additionally adding "HAVING population = MAX(population)" has no effect since it's already true.

I hope i understood it correctly and could clarify others who wondered why the other solutions didnt work.