Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2006

Tip: Looking for answers? Try searching our database.

Qry returning highest number in a group

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grant - 27 May 2006 15:50 GMT
Hello Group,
I have a qry using [WOID] as the criteria to pull up a number of records.  
The criteria is set at 28286.  This produces 8 records.  Another field in the
qry is [PROID].  Of the 8 records, 4 have a [PROID] of 91234 and 4 have 94321.

What I'd like to have happen is the qry will only produce the records with
the greater (highest) number in the [PROID] field..  4 records would be
produced with [PROID] being 94321.  

Is this possible and how would I go about do this?
Thank You
Grant  
Ken Snell (MVP) - 27 May 2006 16:21 GMT
SELECT A.[WOID], A.[PROID]
FROM YourTableName AS A
WHERE A.[WOID] = 28286 AND
A.[PROID] = (SELECT Max(T.[PROID])
FROM YourTableName AS T
WHERE T.[WOID] = A.[WOID]);

Signature

       Ken Snell
<MS ACCESS MVP>

> Hello Group,
> I have a qry using [WOID] as the criteria to pull up a number of records.
[quoted text clipped - 10 lines]
> Thank You
> Grant
Grant - 27 May 2006 17:17 GMT
Hi Ken,
Here's my exact statement which I get an syntax error on:

SELECT tblPNNested.Cert, tblWorkorder.WOID, [tblProcNested-Non].[Item#],
[tblProcNested-Non].Desc, [tblProcNested-Non].Thick,
[tblProcNested-Non].Area, [tblProcNested-Non].PNID, [tblProcNested-Non].PROCID
FROM tblPNNested INNER JOIN (tblWorkorder INNER JOIN [tblProcNested-Non] ON
tblWorkorder.WOID = [tblProcNested-Non].WOID) ON (tblWorkorder.WOID =
tblPNNested.WOID) AND (tblPNNested.[Item#] = [tblProcNested-Non].[Item#])
WHERE (((tblPNNested.Cert)=-1) AND ((tblWorkorder.WOID)=28289) AND
(([tblProcNested-Non].PROCID)=(SELECT Max([tblProcNested-non].PROCID)));

What am I doing wrong?
Thanks
Grant

> SELECT A.[WOID], A.[PROID]
> FROM YourTableName AS A
[quoted text clipped - 17 lines]
> > Thank You
> > Grant
Ken Snell (MVP) - 27 May 2006 21:01 GMT
Your subquery's SQL statement is incomplete. Here is what I posted in my
suggestion (I've excerpted the part for the comparison for PROID):

A.[PROID] = (SELECT Max(T.[PROID])
FROM YourTableName AS T
WHERE T.[WOID] = A.[WOID]);

Here is what you have:

(([tblProcNested-Non].PROCID)=(SELECT
Max([tblProcNested-non].PROCID)));

Notice what is missing after the "Max" part of the statement --you do not
specify the table from which the data are to be drawn, nor do you use the
WOID value to filter the data set in the subquery.

Also, you must use an alias for the tablename in the subquery's SQL
statement so that the query knows you're not using the exact same data set
in the subquery as in the main query. Look again at the posted example I
provided. I am using A as the alias for the table in the main query, and T
as the alias for the table in the subquery.

Therefore, a revised query statement would be something like this:

SELECT tblPNNested.Cert, tblWorkorder.WOID, [tblProcNested-Non].[Item#],
[tblProcNested-Non].Desc, [tblProcNested-Non].Thick,
[tblProcNested-Non].Area, [tblProcNested-Non].PNID,
[tblProcNested-Non].PROCID
FROM tblPNNested INNER JOIN (tblWorkorder INNER JOIN [tblProcNested-Non] ON
tblWorkorder.WOID = [tblProcNested-Non].WOID) ON (tblWorkorder.WOID =
tblPNNested.WOID) AND (tblPNNested.[Item#] = [tblProcNested-Non].[Item#])
WHERE (((tblPNNested.Cert)=-1) AND ((tblWorkorder.WOID)=28289) AND
(([tblProcNested-Non].PROCID)=(SELECT Max(T.PROCID
FROM [tblProcNested-non] AS T WHERE
T.[WOID] = [tblWorkorder].[WOID])));

Signature

       Ken Snell
<MS ACCESS MVP>

> Hi Ken,
> Here's my exact statement which I get an syntax error on:
[quoted text clipped - 38 lines]
>> > Thank You
>> > Grant
Ken Snell (MVP) - 27 May 2006 21:57 GMT
Sorry, inadvertently omitted a parenthesis. Try this:

SELECT tblPNNested.Cert, tblWorkorder.WOID, [tblProcNested-Non].[Item#],
[tblProcNested-Non].Desc, [tblProcNested-Non].Thick,
[tblProcNested-Non].Area, [tblProcNested-Non].PNID,
[tblProcNested-Non].PROCID
FROM tblPNNested INNER JOIN (tblWorkorder INNER JOIN [tblProcNested-Non] ON
tblWorkorder.WOID = [tblProcNested-Non].WOID) ON (tblWorkorder.WOID =
tblPNNested.WOID) AND (tblPNNested.[Item#] = [tblProcNested-Non].[Item#])
WHERE (((tblPNNested.Cert)=-1) AND ((tblWorkorder.WOID)=28289) AND
(([tblProcNested-Non].PROCID)=(SELECT Max(T.PROCID)
FROM [tblProcNested-non] AS T WHERE
T.[WOID] = [tblWorkorder].[WOID])));

Signature

       Ken Snell
<MS ACCESS MVP>

> Your subquery's SQL statement is incomplete. Here is what I posted in my
> suggestion (I've excerpted the part for the comparison for PROID):
[quoted text clipped - 77 lines]
>>> > Thank You
>>> > Grant
Grant - 28 May 2006 01:26 GMT
Thanks Ken..
I didn't understand the alias..
Works perfect..
Grant

> Sorry, inadvertently omitted a parenthesis. Try this:
>
[quoted text clipped - 91 lines]
> >>> > Thank You
> >>> > Grant
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.