Skip to main content
September 24, 2009
Question

Simple cfquery confusing my brain!

  • September 24, 2009
  • 1 reply
  • 911 views

This should be simple, I hope...but my brain is not wrapping around it

SQL DB. Table in db called contactinfo.  column in table called State

I want to be able to run a query to pull all of the states but only once and put a recordcount next to it.

So, say there are three TX clients.  I want to show TX (3)

Does this make any sense?

Thanks in advance

Sharon

www.smdscouts.com

This topic has been closed for replies.

1 reply

ilssac
Inspiring
September 24, 2009

The database features you are searching your brain for are the GROUP BY clause and the count() agregration function.

I.E.

SELECT state, count(*)

FROM contactinfo

GROUP BY state

September 25, 2009

That is wonderful.....second question as my brain has given up on me....how do I ouput the count itself.  Right now it outputs the individual states, but I would like the numbers next to them. ie TX 3

Sharon