- 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
Fetch maximum individual marks for a student with marks1 and marks2 records in MySQL?
For this, use MAX() along with GROUP BY clause. Let us first create a table −
mysql> create table DemoTable -> ( -> StudentEmailId varchar(20), -> Marks1 int, -> Marks2 int -> ); Query OK, 0 rows affected (0.90 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John@gmail.com',45,32); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('John@gmail.com',32,45); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('Carol@gmail.com',32,45); Query OK, 1 row affected (1.64 sec) mysql> insert into DemoTable values('David@gmail.com',45,32); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable ;
This will produce the following output −
+-----------------+--------+--------+ | StudentEmailId | Marks1 | Marks2 | +-----------------+--------+--------+ | John@gmail.com | 45 | 32 | | John@gmail.com | 32 | 45 | | Carol@gmail.com | 32 | 45 | | David@gmail.com | 45 | 32 | +-----------------+--------+--------+ 4 rows in set (0.00 sec)
Here is the query to fetch maximum individual marks for a student with marks1 and marks2 records −
mysql> select StudentEmailId,max(Marks1),max(Marks2) from DemoTable -> group by StudentEmailId;
This will produce the following output −
+-----------------+-------------+-------------+ | StudentEmailId | max(Marks1) | max(Marks2) | +-----------------+-------------+-------------+ | John@gmail.com | 45 | 45 | | Carol@gmail.com | 32 | 45 | | David@gmail.com | 45 | 32 | +-----------------+-------------+-------------+ 3 rows in set (0.00 sec)
- Related Articles
- Get maximum age from records with similar student names in MySQL
- MySQL query for text search with LIKE and OR to fetch records
- Implement MySQL REGEXP to fetch records with . and numbers
- Fetch student records whose result declared 12 days before the current date in MYSQL
- Group the marks of a particular student from a table and display total marks in a separate column for each student?
- MySQL query to find a match and fetch records
- Set custom messages on the basis of a column with student marks in MySQL
- Fetch date records comparing with the current date’s day and month in MySQL
- In an examination , a student has to score 40%marks to pass. He gets 40 marks and fail by 40 marks. Find the maximum number of marks
- How to update document with marks value in MongoDB for student David
- Fetch records containing a specific character twice in MySQL
- Fetch ordered records after a specific limit in MySQL
- MySQL RegExp to fetch records with only a specific number of words
- MySQL to fetch records based on a specific month and year?
- MySQL query to fetch the latest date from a table with date records

Advertisements