You are on page 1of 2

===================================================================================

==========
SCHEMA
===================================================================================
==========
Subject — Id, Name
Student — Id, Name
Result — Id, Sub_id, Stu_id, Marks, Attempt_no

===================================================================================
==========
PROBLEM STATEMENT
===================================================================================
==========
Find out the highest score achieved per subject in the first attempt and who scored
it ?
Sample results should be like
maths 80 Shubham
science 90 kanchan
English 70 yash
===================================================================================
==========
DATA CREATED FOR ABLVE SAMPLE OUTPUT
===================================================================================
==========
DATA ->
student table
id name
1 shubham
2 kanchan
3 yash

subject table
id name
1 maths
2 science
3 english

result table
id sub_id stu_id marks attemp_no
1 1 1 80 1
2 2 1 10 1
3 3 1 10 1
4 1 2 20 1
5 2 2 90 1
6 3 2 20 1
7 1 3 30 1
8 2 3 30 1
9 3 3 70 1

===================================================================================
===========
TRIED THIS BUT stu.name is incorrect
===================================================================================
===========
select sub.name,max(r.marks), stu.name
FROM
student_result.subject sub
INNER JOIN student_result.result r ON sub.id = r.sub_id
INNER JOIN student_result.student stu ON stu.id = r.stu_id
GROUP BY sub.name;

OUTPUT
name max(r.marks) name
english 70 shubham
science 90 shubham
maths 80 shubham

You might also like