Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mahesh.sanka
Starting Member
18 Posts |
Posted - 2013-08-19 : 08:01:15
|
Hi,I am using the following query select top(5) COUNT(incident),name from company_info group by nameorder by COUNT(incident) desc ;to get most repeated incidents.count incident17 ghi15 def14 abc11 z9 xI want to get the same output with out using order by query.Thanks & Regards,Mahesh Kumar Sanka |
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2013-08-19 : 08:11:38
|
That doesn't make sense. TOP always requires an ORDER BY. How else will it know what your definition of "TOP" is? |
|
|
mahesh.sanka
Starting Member
18 Posts |
Posted - 2013-08-19 : 08:16:37
|
Hi ,Thanks for your reply. Then how to get top 5 rows with out using top query.quote: Originally posted by LoztInSpace That doesn't make sense. TOP always requires an ORDER BY. How else will it know what your definition of "TOP" is?
Thanks & Regards,Mahesh Kumar Sanka |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2013-08-19 : 08:31:32
|
You can use ORDER BY then your client can read only the first 5 rows but there's no real reason to do that. What exactly is the issue? Your problem appears to be "I need the top 5 of something but I cannot define what top means".The answer to the question appears to be exactly the query you posted - so why not use that? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-08-19 : 08:53:27
|
quote: Originally posted by mahesh.sanka Hi ,Thanks for your reply. Then how to get top 5 rows with out using top query.quote: Originally posted by LoztInSpace That doesn't make sense. TOP always requires an ORDER BY. How else will it know what your definition of "TOP" is?
Thanks & Regards,Mahesh Kumar Sanka
Without order by clause the result would be randomMadhivananFailing to plan is Planning to fail |
|
|
|
|
|