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 1396
I used two queries:
Query1:
SELECT tbl_purchases.V ehicleID, Min(tbl_purchas es.PurchaseDate ) AS
MinOfPurchaseDa te
FROM tbl_purchases
GROUP BY tbl_purchases.V ehicleID;
Query2:
SELECT Query1.VehicleI D, tbl_purchases.P urchaseID,
Query1.MinOfPur chaseDate, tbl_purchases.C omment
FROM Query1 INNER JOIN tbl_purchases ON (Query1.Vehicle ID =
tbl_purchases.V ehicleID) AND (Query1.MinOfPu rchaseDate =
tbl_purchases.P urchaseDate)
GROUP BY Query1.VehicleI D, tbl_purchases.P urchaseID,
Query1.MinOfPur chaseDate, tbl_purchases.C omment;
Cheers,
Jason Lepack ro***********@h otmail.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.P urchaseID, T1.MinDate,
tbl_purchases.C omment
FROM [SELECT tbl_purchases.V ehicleID, Min(tbl_purchas es.PurchaseDate )
AS MinDate
FROM tbl_purchases
GROUP BY tbl_purchases.V ehicleID]. AS T1 INNER JOIN tbl_purchases ON
(T1.MinDate = tbl_purchases.P urchaseDate) AND (T1.VehicleID =
tbl_purchases.V ehicleID);
Cheers,
Jason Lepack
Jason Lepack wrote:
I used two queries:
Query1:
SELECT tbl_purchases.V ehicleID, Min(tbl_purchas es.PurchaseDate ) AS
MinOfPurchaseDa te
FROM tbl_purchases
GROUP BY tbl_purchases.V ehicleID;
Query2:
SELECT Query1.VehicleI D, tbl_purchases.P urchaseID,
Query1.MinOfPur chaseDate, tbl_purchases.C omment
FROM Query1 INNER JOIN tbl_purchases ON (Query1.Vehicle ID =
tbl_purchases.V ehicleID) AND (Query1.MinOfPu rchaseDate =
tbl_purchases.P urchaseDate)
GROUP BY Query1.VehicleI D, tbl_purchases.P urchaseID,
Query1.MinOfPur chaseDate, tbl_purchases.C omment;
Cheers,
Jason Lepack ro***********@h otmail.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(PurchaseDat e) 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***********@h otmail.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 (specificall y 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" for when
and how to use single quotes and double quotes in ASP?
thanks!
----------------------
SQL = SQL & "WHERE '" &
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
|
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', Table_Name =
'Info_Table', Date_of_Records = @date,
count(*) AS 'Actual Total' ,
|
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 (which I will
paste below)
I have put it on the BeforeUpdate event of a form I am using, but
whenever it is called, I get "Run-time error '13':, Type mismatch
|
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 records in Table3 have to contain all distinct records from Table1 and
Table2 (records where Name2 and Address2 do not already exist in Table3) and
Any help appreciated. I need these queries as a reference, I consider they
|
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 query in my VBA code, like this:
If (result of the query > 0) then
do something
| |
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, but I
can't update record in query or in form. I believe the problem is due
to the source query.
In source query, there is a filter to show the incomplete record
("is null" in delivery date)], but I need to re-use the job no. if the
job is...
|
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 SalesManName
AT Alan Time
|
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 is available on a given date range e.g. from: 1/12/05 to 12/12/05. the second which will run if the first query is unsuccessful e.g. a list of other cars available on the chosen dates. I have been looking at a Microsoft page which I believe may help...
|
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 with MS Access
and VBA. I desperately need help with 2 queries that I am trying to
put together. I want to thank anyone that can help me out with this
situation.
I want to put a select query(Query1) that uses one table and the
criteria would...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |