Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn How many unique? | Selecting
SQL Basics
SectionΒ 1. ChapterΒ 7
single

single

bookHow many unique?

Swipe to show menu

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

Swipe to start coding

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

Solution

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
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt