473,473 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help With Queries In Access

Hey all,

I am struggling with the queries for some tasks I am trying to finish.
being a newbie, I can't seem to figure this out - perhaps you guys can
help:

I have a field: TransactionDate. This field is different for the same
product, but would like to run a query which would return the latest
date. For example:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 2/28/08, 19, 85.00
Glue12, 2/29/08, 29, 75.00
Glue12, 5/1/08,12, 78.00
Eraser10, 2/17/08, 10, 0.25
Eraser10, 2/25/08, 12, 0.53
etc.

What I want to do is find out my last transaction via a Query: I just
want to see this output for the products Glue 12 and Eraser10:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 5/1/08,12, 78.00
Eraser10, 2/25/08, 12, 0.53

Thanks in advance for any or all help!
-Haas
Oct 24 '08 #1
4 1443
Haas

Try this (with a real table name):

Regards

Kevin

SELECT tblTest.ProductName, Max(tblTest.TransactionDate) AS
MaxOfTransactionDate, _
Last(tblTest.QuantitySold) AS LastOfQuantitySold, Last(tblTest.Price) AS
LastOfPrice
FROM tblTest
GROUP BY tblTest.ProductName;
"Haas C" <ha*****@yahoo.comwrote in message
news:00**********************************@l77g2000 hse.googlegroups.com...
Hey all,

I am struggling with the queries for some tasks I am trying to finish.
being a newbie, I can't seem to figure this out - perhaps you guys can
help:

I have a field: TransactionDate. This field is different for the same
product, but would like to run a query which would return the latest
date. For example:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 2/28/08, 19, 85.00
Glue12, 2/29/08, 29, 75.00
Glue12, 5/1/08,12, 78.00
Eraser10, 2/17/08, 10, 0.25
Eraser10, 2/25/08, 12, 0.53
etc.

What I want to do is find out my last transaction via a Query: I just
want to see this output for the products Glue 12 and Eraser10:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 5/1/08,12, 78.00
Eraser10, 2/25/08, 12, 0.53

Thanks in advance for any or all help!
-Haas

Oct 24 '08 #2
KC-Mass wrote:
Haas

Try this (with a real table name):

Regards

Kevin

SELECT tblTest.ProductName, Max(tblTest.TransactionDate) AS
MaxOfTransactionDate, _
Last(tblTest.QuantitySold) AS LastOfQuantitySold, Last(tblTest.Price) AS
LastOfPrice
FROM tblTest
GROUP BY tblTest.ProductName;
I'm not sure exactly how the LAST function works - I thought it just
gave you the record closest to the end of the table, which may not be
the one with the most recent date. In fact, it may return results that
are not actually stored in the same record. For example, if your data
looks like this:

Glue12, 5/1/08,12, 78.00
Glue12, 2/28/08, 19, 85.00
Glue12, 2/29/08, 29, 75.00

Then the above query should return this:

Glue12, 5/1/08, 29, 75.00

Note that the quantity and price returned do not match the quantity and
price from the transaction on 5/1/08.

The way I've always handled situations like this is with two queries.
First, create a query that tells you the most recent transaction date
for each product, something like this:

SELECT ProductName, Max(TransactionDate) AS LatestDate FROM tblTest
GROUP BY ProductName;

Then, create a second query that uses the first query joined to tblTest
with both the ProductName field and the LatestDate field. This should
give you what you want, but if the database is large and those fields
aren't indexed, it could run rather slowly. Note that this method will
return all transactions on the latest date (i.e. if there were two
records for Glue12 with 5/1/08 as the transaction date, it would return
both of them).
Oct 24 '08 #3
On Oct 24, 11:38*am, Haas C <haas...@yahoo.comwrote:
Hey all,

I am struggling with the queries for some tasks I am trying to finish.
being a newbie, I can't seem to figure this out - perhaps you guys can
help:

I have a field: TransactionDate. This field is different for the same
product, but would like to run a query which would return the latest
date. For example:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 2/28/08, 19, 85.00
Glue12, 2/29/08, 29, 75.00
Glue12, 5/1/08,12, 78.00
Eraser10, 2/17/08, 10, 0.25
Eraser10, 2/25/08, 12, 0.53
etc.

What I want to do is find out my last transaction via a Query: I just
want to see this output for the products Glue 12 and Eraser10:

ProductName, TransactionDate, QuantitySold, Price
Glue12, 5/1/08,12, 78.00
Eraser10, 2/25/08, 12, 0.53

Thanks in advance for any or all help!
-Haas
If I understand your question correctly it will take two queries to
get what you want. In this example you will need to sub yout table and
field names.

qry1 - create qry1 and paste this in it

SELECT Table1.ProductNme, Max(Table1.TrxDte) AS MaxOfTrxDte
FROM Table1
GROUP BY Table1.ProductNme;
qry2 - create a second query and paste this sql into it

SELECT Table1.ProductNme, Table1.TrxDte, Table1.QtySold, Table1.Price
FROM Table1 INNER JOIN Query1 ON (Table1.ProductNme =
Query1.ProductNme) AND (Table1.TrxDte = Query1.MaxOfTrxDte);

hope this helps
bobh.

Oct 27 '08 #4
On Oct 27, 1:20*pm, bobh <vulca...@yahoo.comwrote:
On Oct 24, 11:38*am, Haas C <haas...@yahoo.comwrote:


Hey all,
I am struggling with the queries for some tasks I am trying to finish.
being a newbie, I can't seem to figure this out - perhaps you guys can
help:
I have a field: TransactionDate. This field is different for the same
product, but would like to run a query which would return the latest
date. For example:
ProductName, TransactionDate, QuantitySold, Price
Glue12, 2/28/08, 19, 85.00
Glue12, 2/29/08, 29, 75.00
Glue12, 5/1/08,12, 78.00
Eraser10, 2/17/08, 10, 0.25
Eraser10, 2/25/08, 12, 0.53
etc.
What I want to do is find out my last transaction via a Query: I just
want to see this output for the products Glue 12 and Eraser10:
ProductName, TransactionDate, QuantitySold, Price
Glue12, 5/1/08,12, 78.00
Eraser10, 2/25/08, 12, 0.53
Thanks in advance for any or all help!
-Haas

If I understand your question correctly it will take two queries to
get what you want. In this example you will need to sub yout table and
field names.

qry1 - create qry1 and paste this in it

SELECT Table1.ProductNme, Max(Table1.TrxDte) AS MaxOfTrxDte
FROM Table1
GROUP BY Table1.ProductNme;

qry2 - create a second query and paste this sql into it

SELECT Table1.ProductNme, Table1.TrxDte, Table1.QtySold, Table1.Price
FROM Table1 INNER JOIN Query1 ON (Table1.ProductNme =
Query1.ProductNme) AND (Table1.TrxDte = Query1.MaxOfTrxDte);

hope this helps
bobh.- Hide quoted text -

- Show quoted text -
That helps greatly! Thank you!
Nov 13 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
1
by: Job Lot | last post by:
I have written 6 Queries in an Access DB, which are executed in a For Each…Next loop to populate DataSet object. A new DataTable object is created in DataSet for each query, as follows Private...
4
by: dschl | last post by:
Hi, I'm converting an Access 2000 database to Sql Server and must be missing something obvious. Using the Import utility in Sql Server, the Access queries seem to get executed and the...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
1
by: prabhukalyan | last post by:
Hi all, I am not so good in queries. here is my problem 2 tables to store the received items (fabric)-- inwardmaster, inwarddetails and after some processing (Dyeing) the items were...
5
by: LilyRousseau | last post by:
:confused: I could really use some help A Access Database was created and put out in a shared drive--so that anyone could run these queries. I copied the db and made some changes and...
7
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
6
by: troy_lee | last post by:
I am trying to count the total number of units for a given part number that have a Priority rating of 1. Based upon some research, this is what I came up with for my query. Access says that I have...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.