- 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
MySQL group by for separate id without using GROUP BY to remove duplicate column row?
For this, you can use DISTINCT keyword. Let us first create a table −
mysql> create table DemoTable1801 ( Name varchar(20), Score int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1801 values('John',98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John',98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John',99); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('Carol',99); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1801;
This will produce the following output −
+-------+-------+ | Name | Score | +-------+-------+ | John | 98 | | John | 98 | | John | 99 | | Carol | 99 | +-------+-------+ 4 rows in set (0.00 sec)
Here is the query to group by for separate id −
mysql> select distinct Name,Score from DemoTable1801;
This will produce the following output −
+-------+-------+ | Name | Score | +-------+-------+ | John | 98 | | John | 99 | | Carol | 99 | +-------+-------+ 3 rows in set (0.00 sec)
- Related Articles
- Display the record with non-duplicate Id using MySQL GROUP BY and HAVING
- MySQL query to group concat distinct by Id?
- How to remove only the first duplicate row by group in an R data frame?
- Implement MySQL conditional GROUP BY with NOT IN to filter records from duplicate column values
- Get first date from timestamp in MySQL group by another column with duplicate value
- Using GROUP BY and COUNT in a single MySQL query to group duplicate records and display corresponding max value
- Listing all rows by group with MySQL GROUP BY?
- GROUP BY a column in another MySQL table
- GROUP BY the number of rows returned by GROUP BY in MySQL?
- MySQL GROUP BY date when using datetime?
- Group MySQL rows in an array by column value?
- Why should we not use group functions with non-group fields without GROUP BY clause in MySQL SELECT query?
- Limit the count using GROUP BY in MySQL
- How to group array of objects by Id in JavaScript?
- MySQL query to group results by date and display the count of duplicate values?

Advertisements