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

x
?
Solved

Access Query to filter table by Highest Value found in two Fields + iif logic

Posted on 2008-10-08
3
Medium Priority
?
639 Views
Last Modified: 2013-11-28
I have a table in Access with the following fields (see attachment 1):
ParentPart
Version
Route
Component
QtyPer

I would like to write a query using the logic of the following psuedocode:
If Version is null, then return each record for each "ParentPart" where the "Route" is the highest value for that "ParentPart", If Version is not null, then ignore the route and return each record for each "ParentPart" where the "Version" is the highest value for that "ParentPart".

Basically for each parent part I want to grab the entire row if the version number is the highest value in the entire table or if version is null if the route is the highest value.

The second attached file shows what the Output of the query would be for the query.

Thanks for the help







table.jpg
table2.jpg
0
Comment
Question by:Cubemaster
[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
3 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22676003
Try with a derived table:
SELECT b1.*
FROM BOMTable b1 
INNER JOIN (SELECT ParentPart, Max(Version) AS maxVersion, Max(Route) AS maxRoute FROM BOMTable GROUP BY ParentPart) b2
ON b1.ParentPart = b2.ParentPart
AND (b1.Version = b2.maxVersion 
     OR (IsNull(b1.Version)=1 AND b1.Route = b2.maxRoute))

Open in new window

0

Featured Post

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!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

618 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