Solved

Access 2000 - Top Nth function

Posted on 2002-03-27
4
578 Views
Last Modified: 2012-05-05
I am hoping this is a simple problem.  I have a database with a query that shows a unit number, and then every event log entry for that unit.  I am looking to have it return just the most recent result for each unit number.  The query basically looks like this:

SELECT DISTINCT product.unit_number, log.create_date
FROM (Product LEFT JOIN Log ON Product.unit_number = log.Unit_Number)
WHERE Product.Unit_Number = "Variable"
ORDER BY Product.Unit_Number

If I use a SELECT TOP 1 then I just get a single Unit Number returned.  Any help would be much appriciated.  If this question is not as easy as I believe it should be, I will raise the points offered accordingly.
0
Comment
Question by:bluezmasta
4 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 50 total points
Comment Utility
Try this it should select the max date or the highest date.

SELECT DISTINCT product.unit_number, max(log.create_date) as Create_Date
FROM (Product LEFT JOIN Log ON Product.unit_number = log.Unit_Number)
WHERE Product.Unit_Number = "Variable"
ORDER BY Product.Unit_Number


Cheers
Marcus
0
 
LVL 3

Expert Comment

by:SE081398
Comment Utility
first of all what establishes "most recent result"
is this based on date or what?

If you're using the SQL that you've got above then I can see where you may be having some trouble. The top predicate is used on things like top sales figure, top number of orders by date, top number of records based on date or customer. Or like the following.

eg: SELECT DISTINCTROW TOP 10 Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC;

this is out of nwind.mdb in 2000  look at the example in northinds you may be able to figure a few things out.

If the sql you posted isn't the exact sql used then please post it.  it will help to decipher your problem better.



0
 

Expert Comment

by:BarryBulsara
Comment Utility
SELECT product.Unit_Number,max(log.Create_date) as YourDate  
FROM product INNER JOIN log ON product.Unit_Number = log.Unit_Number GROUP BY product.Unit_Number ORDER BY product.Unit_Number




0
 

Author Comment

by:bluezmasta
Comment Utility
Thank you very much.  I must have been having a serious brain cramp.  Using max worked just fine.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

744 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

8 Experts available now in Live!

Get 1:1 Help Now