Solved

Query required

Posted on 2014-01-20
16
318 Views
Last Modified: 2014-01-20
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.
0
Comment
Question by:DColin
  • 8
  • 4
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39793698
Try this:

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 AND Q.CloseTime < Now();

Open in new window

0
 

Author Comment

by:DColin
ID: 39793873
pdebaets:

I get the error message 'Join expression not supported'. Is this an Access problem?
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39794043
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
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 39794065
SELECT Description, BidAmount, Min(BidTime)
FROM tblAuctionBids
Where CloseTime = 0
Order by BidTime
0
 

Author Comment

by:DColin
ID: 39794457
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.
0
 

Author Comment

by:DColin
ID: 39794474
BillDenver,

Here is my test db. I do not have a primary key.
Auction.mdb
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39794512
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
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39794521
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
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:DColin
ID: 39794551
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?
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39794615
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();

Open in new window

0
 

Author Comment

by:DColin
ID: 39794663
Apologies there is an entry error in the in the test database, attached is the correct db.
Auction.mdb
0
 

Author Comment

by:DColin
ID: 39794669
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.
0
 
LVL 12

Accepted Solution

by:
pdebaets earned 500 total points
ID: 39794850
I think I had the Where clause set up wrong... Please try this:

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.BidTime < now() AND Q.CloseTime > Now();
0
 

Author Comment

by:DColin
ID: 39794877
pdebaets,

It now returns only one of the two current auctions.
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39794969
There is only one auction open. The one with the description "B221".
0
 

Author Comment

by:DColin
ID: 39794991
You're correct sorry about that.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

863 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

25 Experts available now in Live!

Get 1:1 Help Now