
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to get the count of a specific value in a column with MySQL?
Let us first create a table −
mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (1.40 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,'John'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values(101,'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(102,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(103,'Chris'); Query OK, 1 row affected (1.05 sec) mysql> insert into DemoTable values(104,'David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(105,'Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(106,'Carol'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(107,'Bob'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-------+ | Id | Name | +------+-------+ | 100 | John | | 101 | Chris | | 102 | Chris | | 103 | Chris | | 104 | David | | 105 | Chris | | 106 | Carol | | 107 | Bob | +------+-------+ 8 rows in set (0.00 sec)
Following is the query to get the count of a specific value in a column i.e. ‘Chris’ here −
mysql> select count(*) from DemoTable where Name='Chris';
This will produce the following output −
+----------+ | count(*) | +----------+ | 4 | +----------+ 1 row in set (0.00 sec)
- Related Articles
- How to count the number of occurrences of a specific value in a column with a single MySQL query?
- How to get the count of each distinct value in a column in MySQL?
- MySQL query to count rows with a specific column?
- How to get the maximum value from a column with alphanumeric strings beginning with specific characters in MYSQL?
- Get the count of a specific value in MongoDB
- Get multiple count in a single MySQL query for specific column values
- Get the count of a specific value in MongoDB quickly
- MySQL CONCAT a specific column value with the corresponding record
- MySQL query to count the number of times a specific integer appears in a column for its corresponding value in another column
- Swap a specific column value in MySQL
- How can I get the number of times a specific word appears in a column with MySQL?
- How to get the primary key “column name” of a specific table in MySQL?
- Get the maximum count of distinct values in a separate column with MySQL
- Can I get the count of repeated values in a column with MySQL?
- Get the maximum value of a column with MySQL Aggregate function

Advertisements