Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
How many unique? | Selecting
SQL Basics
course content

Course Content

SQL Basics

SQL Basics

1. Selecting
2. Filtering
3. Aggregating
4. Sorting
5. Grouping
6. Practicing

bookHow many unique?

But what if we want to calculate the number of unique site visitors? Sounds like a combination of selecting unique and then counting...

Yes, that's the point! To calculate the number of unique observations over a certain column use COUNT(DISTINCT( ... )) statement. For example,

12
SELECT COUNT(DISTINCT(user_id)) FROM visitors
copy

This query will return a single value - the number of unique user_id in the visitors table.

Task

Count the number of different cars models in the audi_cars table.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 7
toggle bottom row

bookHow many unique?

But what if we want to calculate the number of unique site visitors? Sounds like a combination of selecting unique and then counting...

Yes, that's the point! To calculate the number of unique observations over a certain column use COUNT(DISTINCT( ... )) statement. For example,

12
SELECT COUNT(DISTINCT(user_id)) FROM visitors
copy

This query will return a single value - the number of unique user_id in the visitors table.

Task

Count the number of different cars models in the audi_cars table.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 7
toggle bottom row

bookHow many unique?

But what if we want to calculate the number of unique site visitors? Sounds like a combination of selecting unique and then counting...

Yes, that's the point! To calculate the number of unique observations over a certain column use COUNT(DISTINCT( ... )) statement. For example,

12
SELECT COUNT(DISTINCT(user_id)) FROM visitors
copy

This query will return a single value - the number of unique user_id in the visitors table.

Task

Count the number of different cars models in the audi_cars table.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

But what if we want to calculate the number of unique site visitors? Sounds like a combination of selecting unique and then counting...

Yes, that's the point! To calculate the number of unique observations over a certain column use COUNT(DISTINCT( ... )) statement. For example,

12
SELECT COUNT(DISTINCT(user_id)) FROM visitors
copy

This query will return a single value - the number of unique user_id in the visitors table.

Task

Count the number of different cars models in the audi_cars table.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 7
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt