Select Distinct Data in Postgres

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 6 years ago

How many users visited our site yesterday? We can find out by looking at each visit, and limiting this list to a distinct list of users (who may have visited many times). In this lesson we’ll learn how to answer questions like these with the distinct keyword.

[00:01] We'll look at getting distinct information, today. Create a movies' table. We'll insert a couple of titles here. "American History X" gets inserted twice.

[00:12] Maybe, that's OK. Maybe, you can have multiple American History Xs as long as they have different dates. If we select all of this right now, we'll see that we have two American History Xs listed in here.

[00:27] What do we do, though, if we want to get distinct titles? We just select distinct titles. Now, we have different titles, probably still want to make sure that they are in order.

[00:41] We can also do other things, like we can count the number of distinct titles. This is something that's composable with other functions. There, we have three.

egghead
egghead
~ 40 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today