Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Select Distinct Data in Postgres

    Brett CassetteBrett Cassette

    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.

    postgresPostgreSQL
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss