Most Popular Field Values

Results 1 to 2 of 2

Thread: Most Popular Field Values

  1. #1
    Join Date
    Dec 1969

    Default Most Popular Field Values

    I&#039ve read that you can use the following type of query statement to get the most popular values using SQL for say a survey where people put in the size of their company into the field called "size"<BR><BR>query=" Select TOP 3 size, Number=count(*), from survey GROUP BY size ORDER BY Number desc"<BR><BR>I tried this using an Access db and get error messages (the old "Too few parameters. Expected 1" message). Am I coding this wrong or do I need to do this differently for Access?<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Most Popular Field Values

    Try <BR><BR>--<BR><BR>select top 3 count(size) as number<BR>from survey<BR>group by size<BR>order by number desc<BR><BR>--<BR><BR>Now, the order by clause is important. Has to be DESC, otherwise it&#039s sorted based on the group by statement, not the count that you want.<BR><BR>If you have access to SQL Server w/ the Northwind db, try this *tested* query:<BR><BR>select top 3 count(productid) as number, productid from [order details]<BR>group by productid<BR>order by number desc<BR><BR>number productid <BR>----------- ----------- <BR>54 59<BR>51 24<BR>51 31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts