Forum Moderators: coopster

Message Too Old, No Replies

mysql queries, how to perform these

         

Jaunty Edward

4:44 am on Jul 22, 2005 (gmt 0)

10+ Year Member



Hello Everyone,

can anyone tell me if I can make a query in mysql of the following type:

select id,msg,topic,COUNT(*) as stats from table GROUP By topic WHERE stats > 20

I only want to select topics that have over 20 msg.

or may be I can do ORDER BY stats DESC to show the topics that have the highest msg.

I think this is a very frequentry requiered thing for webmasters.

Also is there a way in mySQL i can make a query of the following kind.

select * from table where field is empty.

I am sorry I think my msg is not very clearly explaining what I want but I am sure someone out here will surely show me the way.

Thanks

Mr_Fern

5:27 am on Jul 22, 2005 (gmt 0)

10+ Year Member



I believe that the count(*) in your code will count the table. If you're looking to select topics with only 20 messages or more, you may want to set up a field on the topics table which keeps track of the number of messages each topic has. What is this query being used for exactly?

Also is there a way in mySQL i can make a query of the following kind.

select * from table where field is empty.

Use:

SELECT * FROM {tableName} WHERE {fieldName} = ''

gooflox

2:38 am on Jul 23, 2005 (gmt 0)

10+ Year Member



Have you tried the "HAVING" modifier to the "group by"

Something like:

SELECT id, msg, topic, COUNT(*) as stats
FROM table
GROUP By topic
HAVING stats > 20 ;

Jaunty Edward

5:19 am on Jul 23, 2005 (gmt 0)

10+ Year Member



Hi,

Excellent its works... thank you all of you both my problems are solved.

by adding Having I could make a query where topics of that have a specific number are selected.

Thanks once again.
Jaunty