Solved

Access query - First keyword question

Posted on 2013-06-02
7
405 Views
Last Modified: 2013-06-02
Dear experts -
I have a table of milestones for each milestone of a project. I want to determine the EARLIEST INCOMPLETE record in this table.
What I've done so far:
Create a Subquery, sorting the results by project + date + descriptor.
I created a master query that invokes the subquery and uses the FIRST keyword to find the first occurrence for this project_ID. (I assumed that it was using the sort order built into the subquery.)
It is simply pulling the wrong information.
Any ideas?
Thanks!
0
Comment
Question by:terpsichore
[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
  • 4
  • 3
7 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39214455
You'll need to add an autonumber column to the table like ID.

Then you query will  look something like this:

SELECT SubQ.project, SubQ.datefld, SubQ.descriptor
FROM (SELECT TableX.project, TableX.datefld, TableX.descriptor,  (select count(*) from tableX as x where x.project=tablex.project and x.datefld=tablex.datefld and x.ID<=tablex.ID) AS Seq
   FROM TableX
   WHERE descriptor = "Incomplete"
   ORDER BY TableX.project, TableX.datefld, TableX.descriptor, TableX.ID) SubQ
WHERE SubQ.Seq = 1

Open in new window

0
 

Author Comment

by:terpsichore
ID: 39214485
thanks - can you explain this a little more, and why this would work and why my version wouldn't, perhaps? THANK YOU
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214518
Basically I'm creating a sequence number. And it is a good idea to learn how to do it as the First and Last keywords are unique to Access/JET SQL and nothing else.

I presume that the data is added to you table at random times. This puts them in order and only select the sequence number 1.

That is based on the idea you have an index on the project and datefld when you add the autonumber.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:terpsichore
ID: 39214525
great - sorry to trouble, but one last question before i award you the points - we are migrating to sql server (and also need a consultant for that!) - should we use a different query? THANK YOU
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214545
should we use a different query?

It is easier in MS SQL.

To get a sequence number you use the Row_Number or  Rank functions.
0
 

Author Closing Comment

by:terpsichore
ID: 39214617
Very perceptive, very thorough.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214812
Thanks.

Glad to be of assistance. May your days get brighter and brighter.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

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.
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 different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

734 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