Solved

how to do a sql statment on this question

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

685 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