Fake Apps Table: Show name for max and min value?

Hey everyone! I’ll get straight to it: I want to display the name of both the MOST downloaded app and also the LEAST downloaded one. Ideally, the table would display two rows and two columns: Name and Downloads. I’ve been trying the following code: SELECT name, MAX(downloads), MIN(downloads) FROM fake_apps; but of course is not working.

Link to the “exercise” (not an exercise just review board): https://www.codecademy.com/paths/data-analyst/tracks/dsf-learn-sql/modules/learn-sql-aggregate-functions-75448c0a-1e26-4b19-b967-c8aa75dff67a/lessons/aggregate-functions/exercises/review

Remove the name column and then you can get the max and min downloads.

Otherwise, write two separate queries.

SELECT name, MAX(downloads)
FROM fake_apps;

SELECT name, MIN(downloads)
FROM fake_apps;

Or, google how to write multiple aggregate functions in one sql query.

1 Like

How would it look on a single query if you don’t mind me asking? The two separate query option shows exactly what I want

Hi @santiagograndas ,

it’s good to just try playing with the query and see what happens.

select name, min(downloads), max(downloads)
from fake_apps;

Yes! I’ve been trying out different options including the one you posted. That query only returns one name, the app with the least downloads, the name of the app with the most is not displayed.

Sorry, I should have read your initial question clearly. You can use a “UNION ALL” to join the results together.

SELECT name, MAX(downloads) "Max/Min"
FROM fake_apps
union all
SELECT name, MIN(downloads)
FROM fake_apps;

There is more info here.

Love that, thank you very much. I wasn’t familiar with the union all command.

1 Like