Select Distinct Data in Postgres

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet

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.