Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Help me write this SQL Query

Author  Topic 

bobshishka
Yak Posting Veteran

72 Posts

Posted - 2008-01-29 : 11:33:17
I have a table with many records in it. There is one field called "Nature". How would I select the value that appears the most often in the "Nature" field? The nature field contains text.

For example, this code selects those with more than 10 records...

SELECT count(*) FROM WEBASGN_FULL GROUP BY NATURE HAVING count(*) > 10

I just want the value of the "NATURE" record that occurs the most.

Basically select nature from webasgn_full that occurs the most often in the table....

Thanks

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-29 : 16:11:30
Is this MS Sql Server or Access?

For SqlServer:
select top 1 [nature], count(*) from WEBASGN_FULL GROUP BY [nature] order by count(*) desc

Be One with the Optimizer
TG
Go to Top of Page

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-01-29 : 16:18:44
Its Access, he is in the correct forum... been down this road before: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=96331
Go to Top of Page
   

- Advertisement -