
- 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
SUM corresponding duplicate records in MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris',50); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable values('David',70); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Chris',80); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David',90); Query OK, 1 row affected (0.24 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+-------------+--------------+ | StudentName | StudentMarks | +-------------+--------------+ | Chris | 50 | | David | 70 | | Chris | 80 | | David | 90 | +-------------+--------------+ 4 rows in set (0.00 sec)
Here is the query to sum corresponding duplicate records i.e. the marks of students −
mysql> select StudentName,sum(StudentMarks) from DemoTable group by StudentName;
This will produce the following output −
+-------------+-------------------+ | StudentName | sum(StudentMarks) | +-------------+-------------------+ | Chris | 130 | | David | 160 | +-------------+-------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Add records from corresponding duplicate values in another column with MySQL
- Find average of corresponding records (Product Price) from duplicate product ids in MYSQL
- Get the sum of columns for duplicate records in MySQL
- Find and display duplicate records in MySQL?
- Display highest amount from corresponding duplicate ids in MySQL
- Using GROUP BY and COUNT in a single MySQL query to group duplicate records and display corresponding max value
- How to ignore specific records and add remaining corresponding records (numbers) in MySQL?
- Find average on the basis of corresponding duplicate VARCHAR values in MySQL
- How to delete all the duplicate records in a MySQL table?
- How to remove Duplicate Records except a single record in MySQL?
- Count the occurrences of specific records (duplicate) in one MySQL query
- Which technique is more efficient for replacing duplicate records in MySQL?
- Display an error while inserting duplicate records in a MySQL table
- Find duplicate records in MongoDB?
- MySQL rows concatenation to fetch maximum corresponding value from duplicate IDs?

Advertisements