FAQ: Code Challenge: Queries - Code Challenge 2

This community-built FAQ covers the “Code Challenge 2” exercise from the lesson “Code Challenge: Queries”.

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

Web Development
Data Science

FAQs on the exercise Code Challenge 2

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!

How would I COUNT the number of distinct names that begin with S? (Exercise 3 in Code Challenge 2)

Between distinct and group by which should give the same result, which one is a better practice and why?

SELECT name 
FROM babies WHERE name like 'S%' group by 1 limit 20;
1 Like

must’ve forgotten something along the way, but how come when selecting all the names starting with S they’re all unique without using the ‘distinct’ clause?

Why is not following code not a valid answer?

SELECT DISTINCT name FROM babies

WHERE name BETWEEN ‘S’ AND ‘X’

ORDER BY name

LIMIT 20;

I’m not certain how the results are checked but you’d get a different response without ordering the output which may be why it was not accepted. I’m not sure why you chose ‘X’ as an upper bound for between but you could potentially get the same result if you skipped the ordering though it’s worth bearing in mind that your current query could cause problems with a different dataset (e.g. a smaller one).

.WHAT IS WRONG WITH THIS CODE?
SELECT DISTINCT name

FROM babies

WHERE name LIKE ‘S%’;?

CHECK THE QUESTION AND MAKE SURE TO INCLUDE LIMIT

SELECT DISTINCT name

FROM babies

WHERE name LIKE ‘S%’

LIMIT 20;