

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: CRUD
incomplete
2: Insert Statement
incomplete
3: Auto Increment
incomplete
4: Manual Entry
incomplete
5: Count
incomplete
6: WHERE Clause
incomplete
7: Finding NULL Values
incomplete
8: DELETE
incomplete
9: Danger of Deleting Data
incomplete
10: Update Query in SQL
incomplete
11: Object-Relational Mapping (ORMs)
incomplete
12: Query Practice – User Count
incomplete
13: Query Practice – Country Codes
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We can use a SELECT statement to get a count of the records within a table. This can be very useful when we need to know how many records there are, but we don't particularly care what's in them.
Here's an example in SQLite:
SELECT COUNT(*) FROM employees;
The * in this case refers to a column name. We don't care about the count of a specific column – we want to know the number of total records, so we can use the wildcard (*).
Here is the current state of our users table:
| id | name | age | country_code | username | password | is_admin |
|---|---|---|---|---|---|---|
| 1 | David | 34 | US | DavidDev | insertPractice | 0 |
| 2 | Samantha | 29 | BR | Sammy93 | addingRecords! | 0 |
| 3 | John | 39 | CA | Jjdev21 | welovebootdev | 0 |
| 4 | Ram | 42 | IN | Ram11c | thisSQLcourserocks | 0 |
| 5 | Hunter | 30 | US | Hdev92 | backendDev | 0 |
| 6 | Allan | 27 | US | Alires | iLoveB00tdev | 1 |
| 7 | Lance | 20 | US | LanChr | b00tdevisbest | 0 |
| 8 | Tiffany | 28 | US | Tifferoon | autoincrement | 1 |
Our business strategy team at CashPal wants to know how many users of the app we have. We can't use the id number to calculate the count because user accounts can be deleted!
Use a COUNT(*) statement to retrieve the number of records in the users table.
In this course, stick to using * with COUNT unless the instructions specifically say to count a particular column.