Solved

how to do a sql statment on this question

Posted on 1998-12-10
5
174 Views
Last Modified: 2010-03-19
say I have a table like this

chris 01
chris 02
chris 09
kim   01
kim   08
Gal   04
Gal   06
Gal   07
Gal   08

I want to find the person with most records in this table.
in this case, it will return: Gal 4
How do I do in sql statment to do this. please don't use Top 1 in Access. It needs to be done in 1 query, you could have subquery but it has to be 1 query.

thank you very much

win 100 pts!!! :)
ny971181
0
Comment
Question by:ny971181
5 Comments
 
LVL 7

Expert Comment

by:spiridonov
ID: 1092210
set rowcount 1
select field1,count(field2) from table1
group by field1
order by count(field2) desc
set rowcount 0
0
 
LVL 1

Author Comment

by:ny971181
ID: 1092211
Can we use Set? I'v never heard of this keyword.
I got this error msg: Invalid syntax. Set was hilighted.

Could anyone give me any other suggestion?
Thank you very much

ny971181
0
 
LVL 3

Expert Comment

by:cognition
ID: 1092212
Are you using SQL Server, and what is the client, VB, Crystal etc ?

If you are using SQL server then spridonov's solution will work. You can put all the above in a stored procedure.
0
 
LVL 2

Accepted Solution

by:
odessa earned 100 total points
ID: 1092213
This Works fine I think
select table.f1, ff
from table join (select f1 , count(f2) as ff from table group by f1) as ko on ko.f1 = table.f1
where ff = (select max(ff) from (select f1 , count(f2) as ff from table group by f1) as bb)
group by table1.f1, ff

0
 
LVL 1

Author Comment

by:ny971181
ID: 1092214
Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQl help with selection 14 44
Shop sales Actual vs Forecast 2 26
Link SQL table to Webpage 9 38
Stored procedure 23 0
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now