Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases SQL Reporting by Example Day 1: Joining Tables 8th Grade Teachers

On the `DISTINCT` keyword per column in the instructor's example query

I was a bit confused by this, due to his phrasing; my understanding is the DISTINCT keyword applies to all columns returned in the query, rather than per column, as I thought it sounded like he suggested.

For example, SELECT DISTINCT first_name, DISTINCT last_name would return a syntax error.

Whether or not a row is included while using the DISTINCT keyword would depend on which columns are included and therefore evaluated for 'distinct' values.

SELECT DISTINCT id, first_name, last_name would evaluate if any of the values in each row returned are distinct, which, given the use of the primary key id column, would return every row in the query, as every value for id (an incrementing number) should be distinct.

1 Answer

Steven Parker
Steven Parker
231,269 Points

You are quite right, and DISTINCT applies to all columns returned. So even without using the ID, a query with DISTINCT FIRST_NAME, LAST_NAME would indeed return all teachers even if two had the same first time.

You might want to make a bug report as described on the Support page. If you're the first to report it, it will get you the special Exterminator badge. :beetle: