Solved

how to do a sql statment on this question

Posted on 1998-12-10
5
178 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

776 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