SQLTeam.com | Weblogs | Forums

How to get the maximum value

Hi all,
how to get the maximum value on this query??

select c.cat_name, count(r.cat_id) as Crime_No
from reports r
join categories c
on r.cat_id = c.cat_id
group by c.cat_name
order by 2 desc

select top (1) c.cat_name, count(r.cat_id) as Crime_No
from reports r
join categories c
on r.cat_id = c.cat_id
group by c.cat_name
order by 2 desc

1 Like

Thanks for the community answer. I have resolved the issue using the above commands.

thanks Scott for the answer.
I tried the query but I got an error.

ORA-00923: FROM keyword not found where expected

This is a microsoft sql server forum

select c.cat_name, count(r.cat_id) as Crime_No
from reports r
join categories c
on r.cat_id = c.cat_id
group by c.cat_name
order by 2 desc
fetch first 1 rows only;