Table: id--Subject--Marks 1-----a-------1 2-----a-------2 3-----b-------4 4-----b-------3 5-----b-------2 6-----c-------6 7-----d-------8 8-----d-------1 select id from each subject where max(marks) Answer: id 2 3 6 7
select s.id from subject s inner join ( select subject, MAX(marks) as marks from subject group by subject) dt on s.subject = dt.subject and s.marks = dt.marks
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)