
- 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 do we count the records from MySQL table where column holds duplicate/triplicates data?
Suppose we have the following table named stock_item in which the column quantity is having duplicate values i.e. for item name ‘Notebooks’ and ‘Pencil’, the column ‘Quantity’ is having duplicate values ‘40’ and for items ‘Shirts’, ‘Shoes’ and ‘Trousers’ triplicate value 29 is hold by column ‘quantity’ as shown in the table.
mysql> Select * from stock_item; +------------+----------+ | item_name |quantity | +------------+----------+ | Calculator | 89 | | Notebooks | 40 | | Pencil | 40 | | Pens | 32 | | Shirts | 29 | | Shoes | 29 | | Trousers | 29 | +------------+----------+ 7 rows in set (0.00 sec)
Now with the help of following query we can find the total number of duplicate/triplicate values in column ‘quantity’.
mysql> Select COUNT(quantity) AS duplicate_triplicate -> from stock_item -> group by quantity having duplicate_triplicate> 1; +----------------------+ | duplicate_triplicate | +----------------------+ | 3 | | 2 | +----------------------+ 2 rows in set (0.00 sec)
The result above shows that column ‘quantity’ is having a value that is repeated for three times and a value that is repeated for two times.
- Related Articles
- How do we count the total duplicate records in a column of MySQL table?
- MySQL query to display the count of distinct records from a column with duplicate records
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- Display the count of duplicate records from a column in MySQL and order the result
- How do we find the duplicate values available in a MySQL table?
- Add records from corresponding duplicate values in another column with MySQL
- How to delete a single value from a MySQL table with duplicate records?
- MySQL select only duplicate records from database and display the count as well?
- How can we fetch all the records from a particular MySQL table?
- How to delete all the duplicate records in a MySQL table?
- MySQL query to count number of duplicate values in a table column
- How can we remove a column from MySQL table?
- How can we fetch alternate even-numbered records from MySQL table?
- How can we fetch alternate odd numbered records from MySQL table?
- How can I count unique records from a column in MySQL database?

Advertisements