Newbie query

R

Rohit Nepali

Hi I'm have problem with a simple query. I hope someone can help me.
The table structure is :
Doctor(DName,BirthDate)
Patient(PName,BirthDate)
IsDoctoredBy(DName,PName,LastCheckDate)

Sql query to find the Name of Doctor who has checked maximum patients?

"select max(count(Pname)) from isdoctoredby group by Dname" this query
gives maximum value but I want the Dname too.
"select DName, max(count(Pname)) from isdoctoredby group by Dname" gives
error!!

Thanks in advance.
With regards,
Rohit
 
V

Van T. Dinh

Try: (***untested***)

SELECT TOP 1 IDB.DName, Count(IDB.PName)
FROM IsDoctoredBy AS IDB
GROUP BY IDB.DName
ORDER BY Count(IDB.PName) DESC

(I assumed DName is uniquely indexed, i.e. DName uniquely identifies the
Doctor)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top