473,408 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Distinct Rows ??

Here's my data

FName LName SCORE City State Date
JOE SCHMOE 20 SUSSEX WI 7/9/2005
FRANK GRIMES 19 SUSSEX WI 7/11/2005
DAVID SMITH 18 RACINE WI 7/14/2005
JOE SCHMOE 25 SUSSEX WI 7/10/2005
FRANK GRIMES 18 FRANKSVILLE WI 7/12/2005
DAVID SMITH 19 FRANKSVILLE WI 7/16/2005
CHRIS DAVIS 30 FRANKSVILLE WI 7/16/2005

I basically want to return the unique row where score is the highest.
The data should be returned is:

CHRIS DAVIS 30 FRANKSVILLE WI 7/16/2005
JOE SCHMOE 25 SUSSEX WI 7/10/2005
FRANK GRIMES 19 SUSSEX WI 7/11/2005
DAVID SMITH 19 FRANKSVILLE WI 7/16/2005

I'm using MS Access 2000

Oh, by the way. Is there any way I can return only the top 20 or do I
need to control this via
my .asp script.

Thanks for your help

Jul 13 '06 #1
3 1545
"carrajo" <ca*******@gmail.comwrote in
news:11********************@b28g2000cwb.googlegrou ps.com:
Here's my data

FName LName SCORE City State Date
JOE SCHMOE 20 SUSSEX WI 7/9/2005
FRANK GRIMES 19 SUSSEX WI 7/11/2005
DAVID SMITH 18 RACINE WI 7/14/2005
JOE SCHMOE 25 SUSSEX WI 7/10/2005
FRANK GRIMES 18 FRANKSVILLE WI 7/12/2005
DAVID SMITH 19 FRANKSVILLE WI 7/16/2005
CHRIS DAVIS 30 FRANKSVILLE WI 7/16/2005

I basically want to return the unique row where score is the
highest. The data should be returned is:

CHRIS DAVIS 30 FRANKSVILLE WI 7/16/2005
JOE SCHMOE 25 SUSSEX WI 7/10/2005
FRANK GRIMES 19 SUSSEX WI 7/11/2005
DAVID SMITH 19 FRANKSVILLE WI 7/16/2005

I'm using MS Access 2000

Oh, by the way. Is there any way I can return only the top 20
or do I need to control this via
my .asp script.

Thanks for your help
You have to do this in steps.
The first is to return the maximum score for each user.

SELECT Fname, lname, max(score)
FROM tablename
GROUP BY Fname, Lname;

then go back and get the other info like address and date, for each
instance of Fname, Lname and score.

SELECT * FROM tablename
INNER JOIN queryname
ON tablename.fname = queryname.fname
AND tablename.Lname = queryname.Lname
AND tablename.score = queryname.score
ORDER BY Score DESC;

To limit the resultset, add a TOP n predicate to the select.
as in SELECT TOP 20 * FROM tablename.

If you feel really ambitious and don't want the first step query
around you can try substituting the code so that you get

SELECT TOP 20 * FROM tablename
INNER JOIN (SELECT Fname, lname, max(score)
FROM tablename
GROUP BY Fname, Lname) ALIAS queryname
ON tablename.fname = queryname.fname
AND tablename.Lname = queryname.Lname
AND tablename.score = queryname.score
ORDER BY Score DESC;

Problem is that this type of nested query confuses the Query Design
Viewer, and I don't think it's worth the effort.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 13 '06 #2
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
If you feel really ambitious and don't want the first step query
around you can try substituting the code so that you get

SELECT TOP 20 * FROM tablename
INNER JOIN (SELECT Fname, lname, max(score)
FROM tablename
GROUP BY Fname, Lname) ALIAS queryname
ON tablename.fname = queryname.fname
AND tablename.Lname = queryname.Lname
AND tablename.score = queryname.score
ORDER BY Score DESC;

Problem is that this type of nested query confuses the Query
Design Viewer, and I don't think it's worth the effort.
Eh? It doesn't confuse the QBE at all. At least, as long as you use
[]. As Alias instead of the more widely used ().

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 13 '06 #3
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
>If you feel really ambitious and don't want the first step
query around you can try substituting the code so that you
get

SELECT TOP 20 * FROM tablename
INNER JOIN (SELECT Fname, lname, max(score)
FROM tablename
GROUP BY Fname, Lname) ALIAS queryname
ON tablename.fname = queryname.fname
AND tablename.Lname = queryname.Lname
AND tablename.score = queryname.score
ORDER BY Score DESC;

Problem is that this type of nested query confuses the Query
Design Viewer, and I don't think it's worth the effort.

Eh? It doesn't confuse the QBE at all. At least, as long as
you use []. As Alias instead of the more widely used ().
Thank you for the pointer sir.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ralph Freshour | last post by:
I have a question about the following PHP script - I got it off a web site tutorial on how to count users logged into your site - my question is the $PHP_SELF variable - it writes the name of the...
4
by: Johnson, Shaunn | last post by:
Howdy: Can someone tell what the difference (and why you would use it) is between the following: select distinct on (col_1, col_2), col_1, col_2, col_3
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
2
by: Jim H | last post by:
I am storing incoming data in memory using a DataTable. After I'm done retrieving the data I need to get the distinct rows. I tried using DataTable.Select but that doesn't work. If I have...
1
by: Don Bowman | last post by:
I have a table with a large number of rows (10K in the example below, but >1M in some databases). I would like to find the distinct values for one of the columns. The column is indexed. I would...
3
by: Li Pang | last post by:
Hi, I want to know how to create a dataview from a datatable of DISTINCT data. Thank in advance
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
1
by: Damien | last post by:
I have seen examples of selecting distinct elements by name, but my issue is that I need to get distinct attributes by name. My XML looks like: <root> <file> <rows> <row att1="1" /> <row...
1
by: sampalmer21 | last post by:
Hi, I want to join two tables together and only select the rows that don't have the same customer first name and last name (see my code below). When I run my code with the DISTINCT keyword, it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.