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
Solved

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

Posted on 2008-10-08
3
632 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

860 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