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 |
|
smith2487
Starting Member
9 Posts |
Posted - 2009-06-16 : 11:26:06
|
| Hi Everyone!This is my first post, thanks in advance for the help.I have a query that returns a large number of rows.select * from event where ideventsource = '2AF928DD-E2BB-4CE5-8D1D-DF88EC447F15' One of the columns in the table I'm querying is the 'message' column.I would like to be able to determine which 'message' occurs the most in the rows returned by the query. So I assume I need to include a 'group by' or 'order by count' DESC statement, but I'm not sure.Thanks again,Mark |
|
|
kfluffie
Posting Yak Master
103 Posts |
Posted - 2009-06-16 : 11:30:15
|
| Hi, try this:SELECT COUNT(1) as Count, Message FROM event GROUP BY MessageORDER BY COUNT(1) DESC |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-16 : 11:36:44
|
select message, count(*) as qty from(select message from event where ideventsource = '2AF928DD-E2BB-4CE5-8D1D-DF88EC447F15')dtgroup by messageorder by qty DESC No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-16 : 12:29:03
|
you can simply use:select message,count(*) as qty from event where ideventsource = '2AF928DD-E2BB-4CE5-8D1D-DF88EC447F15'group by messageorder by qty |
 |
|
|
smith2487
Starting Member
9 Posts |
Posted - 2009-06-16 : 15:04:06
|
| thank you for the replies.webfred, you rock!Your query returned exactly what I was looking for!This forum is a great resource. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-17 : 01:27:30
|
Welcome But I think visakh is right.His query will also work for you but with the addition of DESC in group by.Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|