Solved

Query required

Posted on 2014-01-20
16
305 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
Comment Utility
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
Comment Utility
pdebaets:

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

Expert Comment

by:Bill Ross
Comment Utility
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
Comment Utility
SELECT Description, BidAmount, Min(BidTime)
FROM tblAuctionBids
Where CloseTime = 0
Order by BidTime
0
 

Author Comment

by:DColin
Comment Utility
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
Comment Utility
BillDenver,

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

Expert Comment

by:Bill Ross
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:DColin
Comment Utility
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
Comment Utility
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
Comment Utility
Apologies there is an entry error in the in the test database, attached is the correct db.
Auction.mdb
0
 

Author Comment

by:DColin
Comment Utility
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
Comment Utility
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
Comment Utility
pdebaets,

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

Expert Comment

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

Author Comment

by:DColin
Comment Utility
You're correct sorry about that.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Read about achieving the basic levels of HRIS security in the workplace.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

762 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

7 Experts available now in Live!

Get 1:1 Help Now