To simplify your life, you need to uniquely identify the winning Bid record itself. That's why you need an autokey BidID.
I'm going to assume that the BidIDs were assigned in ascending order, so that later BidIDs are higher than earlier ones. This assumption will be true except on initial conversion, may still be true then, and only matters if you have duplicate valid bids for the same amount in a particular auction.
We want the earliest valid bid for each auction that has the highest price of any valid bid for that auction.
Code:
Query1:
SELECT TB.AuctionID, Min(TB.BidID) As WinBID
FROM
tblBids AS TB
INNER JOIN
tblAuctions AS TA
ON TB.AuctionID = TA.AuctionID
WHERE TA.Endtime < Now()
AND TB.BidPrice IN
(SELECT MAX(TB2.BidPrice)
WHERE TB2.AuctionID = TA.AuctionID
AND TB2.BidTIME <= TA.endTIME
AND TB2.BidPrice >= TA.minBiD)
GROUP BY TB.AuctioNID;
You can get the same result using the bidtime, but it will have multiple subselects and look much more complicated. Here's the code that should do it without that assumption... I hope:
Code:
Query1: (alternate)
SELECT TB.AuctionID, TB.BidID As WinBID
FROM
tblBids AS TB
INNER JOIN
tblAuctions AS TA
ON TB.AuctionID = TA.AuctionID
WHERE TA.Endtime < Now()
AND TB.BidPrice IN
(SELECT MAX(TB2.BidPrice)
WHERE TB2.AuctionID = TA.AuctionID
AND TB2.BidTIME <= TA.endTIME
AND TB2.BidPrice >= TA.minBiD)
AND TB.BidTime IN
(SELECT MIN(TB3.BidTime)
WHERE TB3.AuctionID = TA.AuctionID
AND TB3.BidTIME <= TA.endTIME
AND TB3.BidPrice >= TA.minBiD
AND TB3.BidPrice = TB.BidPrice);
Now, each of those queries uniquely identifies the winners (if any). All you have to do is use a simple join to the tblAuction record on one side and the tblBids record on the other, and you can report anything you want.
Code:
SELECT TA.AuctionID, TA.Seller, TA.iid, TB.BidID, TB.Bidder, TB.BidTime, TB.BidPrice
FROM
tblAuctions AS TA
INNER JOIN
(Query1 AS Q1
INNER JOIN
tblBids AS TB
ON Q1.WinBid = TB.BidID)
ON TA.AuctionID = Q1.AuctionID;
And this gets you the completed auctions with no winner.
Code:
SELECT TA.AuctionID, TA.Seller, TA.iid
FROM
tblAuctions AS TA
LEFT JOIN
Query1 AS Q1
ON TA.AuctionID = Q1.AuctionID
WHERE TA.Endtime < Now()
AND Q1.AuctionID IS NULL;