Hi,
Please can you help me with this query which I am struggling with?
Here is a simplified version of the table I am trying to work with
VehicleId, PurchaseId, PurchaseDate, Comment
1, 1, 03/03/2006, 'customer has a big nose'
1, 79, 04/04/2006, 'it's raining'
1, 8, 05/05/2006, 'man, i keep selling this vehicle'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
2, 5, 03/03/2006, 'I wonder what's on TV tonight'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
I need to select only the rows for the first time the vehicle is sold
(specifically I need the comment). I need to return
1, 1, 03/03/2006, 'customer has a big nose'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
Purchase Id cannot be guaranteed to be in ascending date order.
Can anyone help please?
Thanks
Rob 3 1379
I used two queries:
Query1:
SELECT tbl_purchases.VehicleID, Min(tbl_purchases.PurchaseDate) AS
MinOfPurchaseDate
FROM tbl_purchases
GROUP BY tbl_purchases.VehicleID;
Query2:
SELECT Query1.VehicleID, tbl_purchases.PurchaseID,
Query1.MinOfPurchaseDate, tbl_purchases.Comment
FROM Query1 INNER JOIN tbl_purchases ON (Query1.VehicleID =
tbl_purchases.VehicleID) AND (Query1.MinOfPurchaseDate =
tbl_purchases.PurchaseDate)
GROUP BY Query1.VehicleID, tbl_purchases.PurchaseID,
Query1.MinOfPurchaseDate, tbl_purchases.Comment;
Cheers,
Jason Lepack ro***********@hotmail.com wrote:
Hi,
Please can you help me with this query which I am struggling with?
Here is a simplified version of the table I am trying to work with
VehicleId, PurchaseId, PurchaseDate, Comment
1, 1, 03/03/2006, 'customer has a big nose'
1, 79, 04/04/2006, 'it's raining'
1, 8, 05/05/2006, 'man, i keep selling this vehicle'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
2, 5, 03/03/2006, 'I wonder what's on TV tonight'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
I need to select only the rows for the first time the vehicle is sold
(specifically I need the comment). I need to return
1, 1, 03/03/2006, 'customer has a big nose'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
Purchase Id cannot be guaranteed to be in ascending date order.
Can anyone help please?
Thanks
Rob
I now understand access subqueries. They're different from Oracle.
This one query does what you want.
SELECT T1.VehicleID, tbl_purchases.PurchaseID, T1.MinDate,
tbl_purchases.Comment
FROM [SELECT tbl_purchases.VehicleID, Min(tbl_purchases.PurchaseDate)
AS MinDate
FROM tbl_purchases
GROUP BY tbl_purchases.VehicleID]. AS T1 INNER JOIN tbl_purchases ON
(T1.MinDate = tbl_purchases.PurchaseDate) AND (T1.VehicleID =
tbl_purchases.VehicleID);
Cheers,
Jason Lepack
Jason Lepack wrote:
I used two queries:
Query1:
SELECT tbl_purchases.VehicleID, Min(tbl_purchases.PurchaseDate) AS
MinOfPurchaseDate
FROM tbl_purchases
GROUP BY tbl_purchases.VehicleID;
Query2:
SELECT Query1.VehicleID, tbl_purchases.PurchaseID,
Query1.MinOfPurchaseDate, tbl_purchases.Comment
FROM Query1 INNER JOIN tbl_purchases ON (Query1.VehicleID =
tbl_purchases.VehicleID) AND (Query1.MinOfPurchaseDate =
tbl_purchases.PurchaseDate)
GROUP BY Query1.VehicleID, tbl_purchases.PurchaseID,
Query1.MinOfPurchaseDate, tbl_purchases.Comment;
Cheers,
Jason Lepack ro***********@hotmail.com wrote:
Hi,
Please can you help me with this query which I am struggling with?
Here is a simplified version of the table I am trying to work with
VehicleId, PurchaseId, PurchaseDate, Comment
1, 1, 03/03/2006, 'customer has a big nose'
1, 79, 04/04/2006, 'it's raining'
1, 8, 05/05/2006, 'man, i keep selling this vehicle'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
2, 5, 03/03/2006, 'I wonder what's on TV tonight'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
I need to select only the rows for the first time the vehicle is sold
(specifically I need the comment). I need to return
1, 1, 03/03/2006, 'customer has a big nose'
2, 412, 02/02/2006, 'I break for lunch in 10 minutes'
3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
Purchase Id cannot be guaranteed to be in ascending date order.
Can anyone help please?
Thanks
Rob
A few different approaches.
SELECT *
FROM Purchases as A
WHERE PurchaseDate =
(select min(PurchaseDate) from Purchases as B
where A.VehicleID = B.VehicleID)
SELECT *
FROM Purchases as A
WHERE NOT EXISTS
(select * from Purchases as B
where A.VehicleID = B.VehicleID
and A.PurchaseDate B.PurchaseDate)
SELECT *
FROM Purchases as A
WHERE PurchaseID =
(select TOP 1 PurchaseID from Purchases as B
where A.VehicleID = B.VehicleID
order by PurchaseDate)
Roy Harvey
Beacon Falls, CT
On 13 Dec 2006 05:09:34 -0800, ro***********@hotmail.com wrote:
>Hi, Please can you help me with this query which I am struggling with? Here is a simplified version of the table I am trying to work with
VehicleId, PurchaseId, PurchaseDate, Comment
1, 1, 03/03/2006, 'customer has a big nose' 1, 79, 04/04/2006, 'it's raining' 1, 8, 05/05/2006, 'man, i keep selling this vehicle' 2, 412, 02/02/2006, 'I break for lunch in 10 minutes' 2, 5, 03/03/2006, 'I wonder what's on TV tonight' 3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
I need to select only the rows for the first time the vehicle is sold (specifically I need the comment). I need to return
1, 1, 03/03/2006, 'customer has a big nose' 2, 412, 02/02/2006, 'I break for lunch in 10 minutes' 3, 2, 05/05/2006, 'I am the angel of death, destroyer of worlds'
Purchase Id cannot be guaranteed to be in ascending date order.
Can anyone help please? Thanks Rob
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: sah |
last post by:
I need some help with the following query:
DECLARE @SRV VARCHAR(20), @date smalldatetime
SET @SRV = (select @@servername)
SET @date = '20040901'
select Srv_Name = @SRV, DB_Name = 'DB_NAME',...
|
by: Max Harvey |
last post by:
Hi,
I have looked at the example called "Open Parameter queries from code"
from the site http://www.mvps.org/access/queries/qry0003.htm
I made up a test which I though looked pretty close...
|
by: Nicolae Fieraru |
last post by:
I have two tables, they contain:
Table1: ID1, Name1, Address1, Purchase1
Table2: ID2, Name2, Address2, Purchase2
I need a query which creates Table3 with content from Table1 and Table2.
The...
|
by: Nicolae Fieraru |
last post by:
Hi All,
I have a query, Select Count(BoolField) from tblMyTable, Where BoolField =
true.
If I run the query by itself, it returns the number of true records
I want to use the result of that...
|
by: Ryan Hubbard |
last post by:
Is it possible to get the recordset from an open query window? So you
run the query. The window is open. Can vba retrieve this data?
|
by: Apple |
last post by:
1. I want to create an autonumber, my requirement is : 2005/0001
(Year/autonumber), which year & autonumber no. both can auto run.
2. I had create a query by making relation to a table & query,...
|
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID ...
|
by: mharrison |
last post by:
Hello,
I am developing a small java web-based car-pool booking system app which interacts with an access database. I am trying to write 2 queries: The first which will specify whether a given car...
|
by: Doris |
last post by:
It does not look like my message is posting....if this is a 2nd or 3rd
message, please forgive me as I really don't know how this site works.
I want to apologize ahead of time for being a novice...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
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...
| |