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 |
|
ljp099
Yak Posting Veteran
79 Posts |
Posted - 2008-06-04 : 16:04:45
|
| Im trying to select the 5 top documents in the research_downloads table and order them by greatest number desc. The query below is returning the recordset ordered by content_title. Should I be using a count() in the select instead of the TOP and use the count() in the Order By?SELECT Distinct Top 5 [content].content_id, [content].content_title FROM research_downloads INNER JOIN [content] ON = [content].content_id WHERE [content].folder_id=30 AND CHARINDEX('<PrimarySubjectArea>Content</PrimarySubjectArea>', content_html) > 1 Group By [content].content_id, [content].content_title, research_downloads.insert_date ORDER BY ?? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-04 : 16:07:31
|
| What do you mean by "order them by greatest number desc"? What is greatest number?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
ljp099
Yak Posting Veteran
79 Posts |
Posted - 2008-06-04 : 17:08:49
|
| content_id | date10010010010010099999999102103104104101101101With these column values, the results would be ordered:DocId100 (5 total)99 (4 total)101 (3 total)104 (2 total)102 (1 total)103 (1 total) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-05 : 00:23:19
|
| [code]SELECT content_idFROM TableGROUP BY content_idORDER BY COUNT(*) DESC[/code] |
 |
|
|
cruxmagi
Starting Member
38 Posts |
Posted - 2008-06-05 : 02:23:42
|
| SELECT content_id,COUNT(*) as 'Total'FROM TableGROUP BY content_idORDER BY COUNT(*) DESC |
 |
|
|
|
|
|