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.......

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;

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

whats the issue. Not Executed?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.