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
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    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.



    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




    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.

    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.

    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.

    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.