John Nichel <[EMAIL PROTECTED]> wrote on 03/08/2005 04:40:00 PM: > Hi all, > > I have a table which contains amoung other things, search terms used on > our web site. What I'm trying to do is select the count of distinct > search terms in one query. I think this is possible, but I can't seem > to get the syntax quite right. I've tried things like the following.... > > SELECT COUNT ( searchTerms ) AS count, DISTINCT searchTerms..... > SELECT COUNT ( DISTINCT searchTerms ) AS count, searchTerms..... > > But as most of you can probably see from that, it's not working. Can > someone give me a nudge in the right direction? I'll work on limiting > this query to the top ten or so results once (if) I can get this part of
> it working. TIA > > -- > John C. Nichel > KegWorks.com > 716.856.9675 > [EMAIL PROTECTED] > Try something that looks like: SELECT searchTerms, Count(1) as frequency FROM your_table_name_here GROUP by searchTerms ORDER BY frequency DESC LIMIT 10; That will give you the 10 most frequently appearing searchTerms in the table "your_table_name_here". The GROUP BY breaks your results up by unique values (if a searchTerms value appears 3 times then the COUNT(1) will be 3 for that value), the ORDER BY ... DESC puts the highest values first, and the LIMIT 10 stops returning results after it sends you 10 rows. IF you post your actual table definition(s), some sample data, your failed queries, and an example of what you wanted in the first place, we could give you a better answer... Shawn Green Database Administrator Unimin Corporation - Spruce Pine