Intermediate SQL
Jasmin Ludolf
Data Science Content Developer, DataCamp


COUNT()SELECT COUNT(birthdate) AS count_birthdates
FROM people;
|count_birthdates|
|----------------|
|6152 |
SELECT COUNT(name) AS count_names, COUNT(birthdate) AS count_birthdates
FROM people;
|count_names|count_birthdates|
|-----------|----------------|
|6397 |6152 |
COUNT(field_name) counts values in a fieldCOUNT(*) counts records in a table* represents all fieldsSELECT COUNT(*) AS total_records
FROM people;
|total_records|
|-------------|
|8397 |
DISTINCT removes duplicates to return only unique valuesSELECT language
FROM films;
|language |
|---------|
|Danish |
|Danish |
|Greek |
|Greek |
|Greek |
films table?
SELECT DISTINCT language
FROM films;
|language |
|---------|
|Danish |
|Greek |
COUNT() with DISTINCT to count unique valuesSELECT COUNT(DISTINCT birthdate) AS count_distinct_birthdates
FROM people;
|count_distinct_birthdates|
|-------------------------|
|5398 |
COUNT() includes duplicatesDISTINCT excludes duplicatesIntermediate SQL