
- 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
MySQL query to get count of each fileid entry in a table with Id and FileIDs?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FileID int ) AUTO_INCREMENT=100; Query OK, 0 rows affected (1.36 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(FileID) values(70); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.32 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----+---------+ | Id | FileID | +-----+---------+ | 100 | 50 | | 101 | 60 | | 102 | 50 | | 103 | 70 | | 104 | 60 | | 105 | 50 | +-----+---------+ 6 rows in set (0.00 sec)
Following is the query to get a count of each FileID entry in a table −
mysql> select FileID,COUNT(FieldId) AS EntryCount from DemoTable group by FileID;
This will produce the following output −
+---------+------------+ | FileID | EntryCount | +---------+------------+ | 50 | 3 | | 60 | 2 | | 70 | 1 | +---------+------------+ 3 rows in set (0.00 sec)
- Related Articles
- Get Last Entry in a MySQL table?
- Get the count of two table fields in a single MySQL query?
- How to get number of rows in a table without using count(*) MySQL query?
- Updating last entry of a particular ID in MySQL
- How to get the data associated with the maximum id in a MySQL table?
- MySQL Query to get count of unique values?
- Apply MySQL query to each table in a database?
- How to find string count of a particular id in a column using a MySQL query?
- MySQL query to count number of duplicate values in a table column
- MySQL query to count the duplicate ID values and display the result in a separate column
- MySQL query to get the count of distinct records in a column
- MySQL query to delete a record with the lowest ID?
- MySQL query to get max id from varchar type and the values in numeric?
- Count number of rows in each table in MySQL?
- Adding a unique id for each entry in JSON object in JavaScript

Advertisements