i have the following tables: VISITS: vid, pid, date PATIENT: pid, pname, age, gender . what i want is to get the patient with more visits by using a count and a max function. i did the count with this query:
select Patient.pname, count (Visits.pid) as PatientsVisits from ( Patient inner join Visits on Patient.pid = Visits.pid) group by Patient.pname
So my output displays the patient's name and the number of visits each one has.
So how can i get the max value ?? ps: im using sql server