Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access07 - Query Max 2 items from another query

Posted on 2014-01-26
6
Medium Priority
?
306 Views
Last Modified: 2014-01-26
Hello all,
Last night I posted a question regarding pulling the last Item of all Items.  Got that to work...Thanks....  However, I took that theory and tried going to the next step

I have a query that is a combination of several tables.  I am wanting to get the Last input of each Item ([MachPollPositionID]).  I tried this
SELECT InfoDtailID, MachPollPositionID, MachPulledYN, MAX(MachPollPositionID) AS MaxPollPos, MAX(BusDay) AS MaxBusDay
FROM qry_InfoDetails_LastPull
WHERE (((qry_InfoDetails_LastPull.MachPulledYN)=TRUE))
GROUP BY qry_InfoDetails_LastPull.InfoDtailID, qry_InfoDetails_LastPull.MachPollPositionID, qry_InfoDetails_LastPull.MachPulledYN;

Open in new window


However, I am getting all the Items MachPollPositionID

My source query's data looks like this:

FIELDS (COLUMNS Below)
InfoDtailID
InfoID
MachPollPositionID
AmtIn
MachPulledYN
ShiftID
InfoDate
MachinePoll
BusDay

12      1      1      $0.00      Yes      1      1/1/2014 3:43:46 PM      1      1/1/2014
13      1      2      $0.00      Yes      1      1/1/2014 3:43:46 PM      2      1/1/2014
14      1      3      $0.00      Yes      1      1/1/2014 3:43:46 PM      3      1/1/2014
15      1      4      $0.00      Yes      1      1/1/2014 3:43:46 PM      4      1/1/2014
16      1      5      $0.00      Yes      1      1/1/2014 3:43:46 PM      5      1/1/2014
32      5      1      $0.00      Yes      6      1/22/2014 12:31:59 AM      1      1/21/2014
36      5      5      $0.00      Yes      6      1/22/2014 12:31:59 AM      5      1/21/2014

What I expected is that my new query would have pulled for PollPositionID the date:
1  1/21/2014
2  1/1/2014
3  1/1/2014
4  1/1/2014
5  1/21/2014

However, I'm simply ending up with the same query as my results above....It's not giving me the MAX date for each PollPositionID
0
Comment
Question by:wlwebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
Lawrence Barnes earned 1600 total points
ID: 39809991
It looks like you are grouping on the InfoDtailID...this is different in each table right?  You will have to remove it from your final query if you want the last date across all tables.
0
 
LVL 2

Expert Comment

by:SickSkilz
ID: 39809997
Have you tried adding this to the where clause?
MachPollPositionID =MAX(MachPollPositionID)
0
 

Author Comment

by:wlwebb
ID: 39809998
LVBarnes
Uggh....So is there a way to get that InfoDtailID for the records that it does select?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Assisted Solution

by:SickSkilz
SickSkilz earned 400 total points
ID: 39810010
Yes, but you need to do it as 2 query steps.  Step 1, get the query to return the uniquly identifying fields (id and maybe date).  Step 2, join the results of that query to this one to get the full details of those records.
0
 

Author Closing Comment

by:wlwebb
ID: 39810015
Thanks.... Looks like that got most of what I needed
0
 
LVL 5

Expert Comment

by:Lawrence Barnes
ID: 39810076
Thanks for the help SickSkilz.

WlWebb I looked at your original query and modified it to give you the ID for the max day.  I'm not familiar with your data though so you'll want to verify the joins.
SELECT lp.MachPollPositionID, lp.MachPulledYN, lp.MaxPollPOS, lp.MaxBusDay, lpbid.InfoDtailID as MaxInfoDtailID
FROM (
SELECT MachPollPositionID, MachPulledYN, MAX(MachPollPositionID) AS MaxPollPos, MAX(BusDay) AS MaxBusDay
FROM qry_InfoDetails_LastPull
WHERE (((qry_InfoDetails_LastPull.MachPulledYN)=TRUE))
GROUP BY qry_InfoDetails_LastPull.MachPollPositionID, qry_InfoDetails_LastPull.MachPulledYN) lp
INNER JOIN (
SELECT InfoDtailID, MachPollPositionID, MachPulledYN, MAX(MachPollPositionID) AS MaxPollPosByID, MAX(BusDay) AS MaxBusDayByID
FROM qry_InfoDetails_LastPull
WHERE (((qry_InfoDetails_LastPull.MachPulledYN)=TRUE))
GROUP BY qry_InfoDetails_LastPull.InfoDtailID, qry_InfoDetails_LastPull.MachPollPositionID, qry_InfoDetails_LastPull.MachPulledYN) lpbid ON lp.MaxPollPOS=lpbid.MaxPollPOSByID AND lp.MaxBusDay=lpbid.MaxBusDayByID

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

610 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