
- 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 find the duplicate values available in a MySQL table?
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’ 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 the following query, we can find the duplicate values in column ‘quantity’ along with the name of items.
mysql> Select distinct g.item_name,g.quantity from stock_item g -> INNER JOIN Stock_item b ON g.quantity = b.quantity -> WHERE g.item_name<>b.item_name; +-----------+----------+ | item_name | quantity | +-----------+----------+ | Pencil | 40 | | Notebooks | 40 | | Shoes | 29 | | Trousers | 29 | | Shirts | 29 | +-----------+----------+ 5 rows in set (0.00 sec)
- Related Articles
- How can we find the duplicate values available in a MySQL table by using JOINS?
- How do we count the total duplicate records in a column of MySQL table?
- How do we count the records from MySQL table where column holds duplicate/triplicates data?
- How can we update values in a MySQL table?
- How can we update the values in one MySQL table by using the values of another MySQL table?
- How to remove duplicate values from a MySQL table using LEFT JOIN?
- How to delete the duplicate values stored in reverse order from MySQL table?
- Selecting the top occurring entries in MySQL from a table with duplicate values?
- MySQL query to count number of duplicate values in a table column
- How can we add values into the columns of a MySQL table?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- How to delete all the duplicate records in a MySQL table?
- How can we update any value in MySQL view as we can update the values in MySQL table?
- Find duplicate column values in MySQL and display them
- Can we insert records in a MySQL table without auto_increment values?

Advertisements