User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 422,977 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,934 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 2077 | Replies: 2
Reply
Join Date: Jul 2006
Posts: 17
Reputation: newMeg is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

Help Need Help on SQL Query for select statement

  #1  
Jul 7th, 2006
Hi,I'm new to daniweb forum. I hope someone could help.

I have a table called Caller which has a field called Area. I need to select the value of the record in this field that repeats the most. For example

Area
Sel
KL
Sel
Sel
Pen
KL

which means i want the answer as Sel because Sel is the higest number that repeated in the Area Column which is three(3) times. KL repeated twice and Pen once. I want to be able to write an SQL statement that could do this.

Can someone help pls. I've tried max but it didnt work. Thank you
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 59
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Need Help on SQL Query for select statement

  #2  
Jul 7th, 2006
select top 1 
	area, countarea 
from(

	select 
		area, count(area) countarea 
	from 
		callers 
	group by 
		area

	) areacount
 
 order by 
	countarea desc
Last edited by hollystyles : Jul 7th, 2006 at 7:36 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Jul 2006
Posts: 17
Reputation: newMeg is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

Re: Need Help on SQL Query for select statement

  #3  
Jul 9th, 2006
Hi hollystyles,

thanx for the great help.It works.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 3:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC