Solved

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

Posted on 2008-10-08
3
631 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
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now