- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
Let us first create a table −
mysql> create table DemoTable723 (Value int); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable723 values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable723 values(200); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable723 values(200); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable723 values(100); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable723 values(300); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable723 values(400); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable723 values(400); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable723 values(600); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable723 values(400); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable723 values(200); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable723;
This will produce the following output -
+-------+ | Value | +-------+ | 100 | | 200 | | 200 | | 100 | | 300 | | 400 | | 400 | | 600 | | 400 | | 200 | +-------+ 10 rows in set (0.00 sec)
Following is the query to select a value from MySQL database only if it exists once from a column with duplicate and non-duplicate values −
mysql> select *from DemoTable723 group by Value having count(Value)=1;
This will produce the following output -
+-------+ | Value | +-------+ | 300 | | 600 | +-------+ 2 rows in set (0.00 sec)
- Related Articles
- Find and display duplicate values only once from a column in MySQL
- Python – Display only non-duplicate values from a DataFrame
- How to order return duplicate column values only once in MySQL?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- MySQL select only duplicate records from database and display the count as well?
- MySQL query to skip the duplicate and select only one from the duplicated values
- Return only a single row from duplicate rows with MySQL
- How to select only non - numeric values from varchar column in MySQL?
- MySQL select only a single value from 5 similar values?
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- How to select distinct value from one MySQL column only?
- How to SELECT all values from a table only once if they're duplicated?
- Python Pandas – Create a subset and display only the last entry from duplicate values
- How to check if an R matrix column contains only duplicate values?

Advertisements