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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select value that most occur

Author  Topic 

voliveira
Starting Member

5 Posts

Posted - 2006-12-05 : 08:27:52
Hi everyone,

sorry for the stupid question, but i've been looking for this answer for a while.
I have a table like this

ID value
1 5
2 3
3 19
4 5
5 5
6 2
7 5

I'd like to select the value the most occur in this table.
In this case would be the number 5.

How can i do that using the SELECT command?
Sorry again for the stupid question.

Thanks and regards,

Vinicius Oliveira

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 08:29:00
select value, count(*) from yourtablenamehere
order by 2 desc

select top 1 value, count(*) from yourtablenamehere
order by 2 desc


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-12-05 : 08:36:45
Add to Peso's ... group by value

Jay
to here knows when
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 08:39:52
Thanks!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

voliveira
Starting Member

5 Posts

Posted - 2006-12-05 : 08:56:32
Thank you very much.
Worked fine.

regards,

Vinicius Oliveira
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-05 : 10:23:43
You need to Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -