I want to find who is the heaviest borrower among the student and displaying Sname and heavy count.
I have the following tables.
tablename student having attributes SID,Sname,Spho.
tablename sborrow having attributes SID,CDID,borrow_date,return_date.
tablename Cd having attributes CDID,title.
I have executed the following query in Mysql but it gives me only the count properly and name as different.
Query->SELECT Sname,max(Quantity) as stud from (select Sname, count(CDID) as Quantity from student NATURAL JOIN sborrow group by SID) as stud;
please help me.......

2 Years
Discussion Span
Last Post by janissantony

select stuid.* from
(select s.SID,s.Sname,s.Spho,count(c.CDID) as CNTVAL
from student s
join sborrow sb on sb.SID = s.SID
join Cd c on c.CDID = sb.CDID
grop by s.SID) as stud
order by stud.CNTVAL asc
limit 0,1;

Edited by Mahesh57


Sorry I tried with the query....I'm not getting the expected answer.


not tried but you may try

select SID, count() from student s, sborrow b
where s.SID = b.SID
group by s.SID
order by count(
) desc
limit 1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.