DColin
asked on
Query required
Hi Experts,
I have an Access database containing the table tblAuctionBids, the fields are as follows:
Description (description of the item being bid on)
BidTime (date/time a bid was received)
CloseTime (date/time the auction closes)
BidAmount (amount being bid)
I need a query that will return rows of opening bids on all currently active auctions. By opening bid I mean the first/earliest bid taken on an item and by currently active auctions I mean auctions that have not closed yet. Thanks.
I have an Access database containing the table tblAuctionBids, the fields are as follows:
Description (description of the item being bid on)
BidTime (date/time a bid was received)
CloseTime (date/time the auction closes)
BidAmount (amount being bid)
I need a query that will return rows of opening bids on all currently active auctions. By opening bid I mean the first/earliest bid taken on an item and by currently active auctions I mean auctions that have not closed yet. Thanks.
ASKER
pdebaets:
I get the error message 'Join expression not supported'. Is this an Access problem?
I get the error message 'Join expression not supported'. Is this an Access problem?
Hi,
Post a sample of your database and I'll show you how. It does not appear that you have a primary key in your table.
Regards,
Bill
Post a sample of your database and I'll show you how. It does not appear that you have a primary key in your table.
Regards,
Bill
SELECT Description, BidAmount, Min(BidTime)
FROM tblAuctionBids
Where CloseTime = 0
Order by BidTime
FROM tblAuctionBids
Where CloseTime = 0
Order by BidTime
ASKER
murphey2,
I am getting the error message:
You tried to execute a query that does not include the specified expression 'Description' as part of an aggregate function.
When I run your query. It seems to be Min(BidTime) that is causing the problem because when I remove the BidTime references it will run without error.
I am getting the error message:
You tried to execute a query that does not include the specified expression 'Description' as part of an aggregate function.
When I run your query. It seems to be Min(BidTime) that is causing the problem because when I remove the BidTime references it will run without error.
ASKER
Hi,
See attached.
The OpenBidsQ gets the time of the last bid for Open Bids. This query is used in MaxOpenBidQ to get the actual bid that matches the time.
Regards,
Bill
Auction1.mdb
See attached.
The OpenBidsQ gets the time of the last bid for Open Bids. This query is used in MaxOpenBidQ to get the actual bid that matches the time.
Regards,
Bill
Auction1.mdb
Hi,
BTW - it's good practice to put a primary key in ALL access tables. You can use a counter (Autonumber) field.
Best regards,
Bill
BTW - it's good practice to put a primary key in ALL access tables. You can use a counter (Autonumber) field.
Best regards,
Bill
ASKER
BillDenver,
Thanks for your reply. I need the first bid for all open auctions not the last bid.
I am using Visual Basic to query the database and use the sql query to populate a DataTable object. Does your solution provide me with an sql query?
Thanks for your reply. I need the first bid for all open auctions not the last bid.
I am using Visual Basic to query the database and use the sql query to populate a DataTable object. Does your solution provide me with an sql query?
Thanks for the file. This should work:
SELECT Q.Description, Q.BidAmount
FROM tblAuctionBids As Q INNER JOIN
(SELECT Description, Min(Bidtime) As MinBidTime
FROM tblAuctionBids
GROUP BY Description) As T
ON Q.Description=T.Description AND Q.BidTime = T.MinBidTime WHERE Q.CloseTime < Now();
ASKER
Apologies there is an entry error in the in the test database, attached is the correct db.
Auction.mdb
Auction.mdb
ASKER
pdebaets
Apologies there is an error in the test db. Please see my previous post for the corrected db.
My test db contains 3 auctions, two current and one expired. When I run your query I get one current and one expired auction returned rather that two current.
Apologies there is an error in the test db. Please see my previous post for the corrected db.
My test db contains 3 auctions, two current and one expired. When I run your query I get one current and one expired auction returned rather that two current.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pdebaets,
It now returns only one of the two current auctions.
It now returns only one of the two current auctions.
There is only one auction open. The one with the description "B221".
ASKER
You're correct sorry about that.
Open in new window