FAQ: Aggregate Functions - Max / Min

This community-built FAQ covers the “Max / Min” exercise from the lesson “Aggregate Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development
Data Science

Learn SQL

FAQs on the exercise Max / Min

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

should these commands return the same?? can’t I use aggregate function in conditioning??

select max(price) from fake_apps;
–>
SELECT price
FROM fake_apps
where price=MAX(price);

1 Like

When you use max(category) on fake_apps, the answer that pops is weather. What does this represent? Does this imply that weather is the most common category?

1 Like

For all practical purposes, if I wanted to know the least popular items in a shop, for example, I couldn’t really use SELECT MIN(item) FROM shop because the results do not include items that sold 0 times, therefore no value to return. What could be a code to return items that sold 0 times, as well as the lowest-selling items?

I believe SELECT MAX(category) FROM fake_apps; is returning Weather because weather is the last thing in the category alphabetically.

To find the most common category, calling for distinct categories and count(*) from fake_apps group by category seems to return the popularity or “hits” of each category.

SELECT distinct category, count(*) AS “Hits”
FROM fake_apps
GROUP BY category
ORDER BY “Hits” DESC
LIMIT 5;

This returns the top 5 most popular categories of fake_apps.

category Hits
Games 17
Education 13
Travel 12
Sports 11
Photo & Video 10
1 Like