From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Counting rows

Counting rows

- [Instructor] You can use the COUNT function to count rows instead of listing them. For this lesson, we'll use the World database. I'm here in MySQL Workbench, and I'm connected with my admin connection. And I'll type USE world and execute that. Now I will select COUNT, and I'll put an asterisk in the parentheses from Country. And when I execute this, you notice I get a number in my result, 239. What the COUNT function does is it returns the number of rows in a result set. And the asterisk is actually a special case that will count all of the rows. Now I can use a WHERE clause and only count some of the rows and say where population is greater than one million. And when I execute that, I now get 154 instead. And if I want 100 million, I can just add a couple of zeroes and now just count rows where the population is greater than 100 million and I execute that. And now I only get 10 countries. Or I can say AND Continent equals Europe. And when I execute that, I now just get one…

Contents