Forum Moderators: coopster

Message Too Old, No Replies

SQL question, re: group and count

PHP people are smart

         

httpwebwitch

2:27 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there is no forum for SQL questions, so I've posted it here.

I have a database containing thousands of words, one word per row. Words are repeated. I need to group and count them, to produce a chart like this:

I (231)
the (175)
if (156)
or (135)
...
trouble (3)
ambidextrous (1)
flamboyancy (1)

How do I do that?
I assume it's a combo using GROUP BY, COUNT, ORDER BY... but I'm not really so adept at SQL so I'd appreciate some tips.

incywincy

2:44 pm on May 26, 2004 (gmt 0)

10+ Year Member



you could try

select distinct word, count(*) from table_name group by word, order by 2;

timster

2:51 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there is no forum for SQL questions, so I've posted it here.

And having one wouldn't be a bad idea. I've noticed questions about SQL and Regex just get asked here and there.

I have a database containing thousands of words, one word per row. Words are repeated. I need to group and count them, to produce a chart like this:

Here it is:

select your_field, count(*) as "total" from iep
group by your_field
order by total DESC

httpwebwitch

4:07 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that worked. Thanks!